org.springframework.scheduling.support.SimpleTriggerContext Java Examples
The following examples show how to use
org.springframework.scheduling.support.SimpleTriggerContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConcurrentTaskScheduler.java From spring-analysis-note with MIT License | 6 votes |
public ScheduledFuture<?> schedule(Runnable task, final Trigger trigger) { ManagedScheduledExecutorService executor = (ManagedScheduledExecutorService) scheduledExecutor; return executor.schedule(task, new javax.enterprise.concurrent.Trigger() { @Override @Nullable public Date getNextRunTime(@Nullable LastExecution le, Date taskScheduledTime) { return (trigger.nextExecutionTime(le != null ? new SimpleTriggerContext(le.getScheduledStart(), le.getRunStart(), le.getRunEnd()) : new SimpleTriggerContext())); } @Override public boolean skipRun(LastExecution lastExecution, Date scheduledRunTime) { return false; } }); }
Example #2
Source File: ConcurrentTaskScheduler.java From java-technology-stack with MIT License | 6 votes |
public ScheduledFuture<?> schedule(Runnable task, final Trigger trigger) { ManagedScheduledExecutorService executor = (ManagedScheduledExecutorService) scheduledExecutor; return executor.schedule(task, new javax.enterprise.concurrent.Trigger() { @Override @Nullable public Date getNextRunTime(@Nullable LastExecution le, Date taskScheduledTime) { return (trigger.nextExecutionTime(le != null ? new SimpleTriggerContext(le.getScheduledStart(), le.getRunStart(), le.getRunEnd()) : new SimpleTriggerContext())); } @Override public boolean skipRun(LastExecution lastExecution, Date scheduledRunTime) { return false; } }); }
Example #3
Source File: JobConfiguration.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Only set next execution time if the job is not continuous. */ public void setNextExecutionTime( Date nextExecutionTime ) { if ( cronExpression == null || cronExpression.equals( "" ) || cronExpression.equals( "* * * * * ?" ) ) { return; } if ( nextExecutionTime != null ) { this.nextExecutionTime = nextExecutionTime; } else { this.nextExecutionTime = new CronTrigger( cronExpression ).nextExecutionTime( new SimpleTriggerContext() ); } }
Example #4
Source File: ConcurrentTaskScheduler.java From lams with GNU General Public License v2.0 | 5 votes |
public ScheduledFuture<?> schedule(Runnable task, final Trigger trigger) { ManagedScheduledExecutorService executor = (ManagedScheduledExecutorService) scheduledExecutor; return executor.schedule(task, new javax.enterprise.concurrent.Trigger() { @Override public Date getNextRunTime(LastExecution le, Date taskScheduledTime) { return (trigger.nextExecutionTime(le != null ? new SimpleTriggerContext(le.getScheduledStart(), le.getRunStart(), le.getRunEnd()) : new SimpleTriggerContext())); } @Override public boolean skipRun(LastExecution lastExecution, Date scheduledRunTime) { return false; } }); }
Example #5
Source File: ConcurrentTaskScheduler.java From spring4-understanding with Apache License 2.0 | 5 votes |
public ScheduledFuture<?> schedule(Runnable task, final Trigger trigger) { ManagedScheduledExecutorService executor = (ManagedScheduledExecutorService) scheduledExecutor; return executor.schedule(task, new javax.enterprise.concurrent.Trigger() { @Override public Date getNextRunTime(LastExecution le, Date taskScheduledTime) { return trigger.nextExecutionTime(le != null ? new SimpleTriggerContext(le.getScheduledStart(), le.getRunStart(), le.getRunEnd()) : new SimpleTriggerContext()); } @Override public boolean skipRun(LastExecution lastExecution, Date scheduledRunTime) { return false; } }); }
Example #6
Source File: ScheduledAnnotationBeanPostProcessorTests.java From spring-analysis-note with MIT License | 4 votes |
@Test public void cronTaskWithZone() { BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class); BeanDefinition targetDefinition = new RootBeanDefinition(CronWithTimezoneTestBean.class); context.registerBeanDefinition("postProcessor", processorDefinition); context.registerBeanDefinition("target", targetDefinition); context.refresh(); ScheduledTaskHolder postProcessor = context.getBean("postProcessor", ScheduledTaskHolder.class); assertEquals(1, postProcessor.getScheduledTasks().size()); Object target = context.getBean("target"); ScheduledTaskRegistrar registrar = (ScheduledTaskRegistrar) new DirectFieldAccessor(postProcessor).getPropertyValue("registrar"); @SuppressWarnings("unchecked") List<CronTask> cronTasks = (List<CronTask>) new DirectFieldAccessor(registrar).getPropertyValue("cronTasks"); assertEquals(1, cronTasks.size()); CronTask task = cronTasks.get(0); ScheduledMethodRunnable runnable = (ScheduledMethodRunnable) task.getRunnable(); Object targetObject = runnable.getTarget(); Method targetMethod = runnable.getMethod(); assertEquals(target, targetObject); assertEquals("cron", targetMethod.getName()); assertEquals("0 0 0-4,6-23 * * ?", task.getExpression()); Trigger trigger = task.getTrigger(); assertNotNull(trigger); assertTrue(trigger instanceof CronTrigger); CronTrigger cronTrigger = (CronTrigger) trigger; Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+10")); cal.clear(); cal.set(2013, 3, 15, 4, 0); // 15-04-2013 4:00 GMT+10 Date lastScheduledExecutionTime = cal.getTime(); Date lastActualExecutionTime = cal.getTime(); cal.add(Calendar.MINUTE, 30); // 4:30 Date lastCompletionTime = cal.getTime(); TriggerContext triggerContext = new SimpleTriggerContext( lastScheduledExecutionTime, lastActualExecutionTime, lastCompletionTime); cal.add(Calendar.MINUTE, 30); cal.add(Calendar.HOUR_OF_DAY, 1); // 6:00 Date nextExecutionTime = cronTrigger.nextExecutionTime(triggerContext); assertEquals(cal.getTime(), nextExecutionTime); // assert that 6:00 is next execution time }
Example #7
Source File: ScheduledAnnotationBeanPostProcessorTests.java From java-technology-stack with MIT License | 4 votes |
@Test public void cronTaskWithZone() { BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class); BeanDefinition targetDefinition = new RootBeanDefinition(CronWithTimezoneTestBean.class); context.registerBeanDefinition("postProcessor", processorDefinition); context.registerBeanDefinition("target", targetDefinition); context.refresh(); ScheduledTaskHolder postProcessor = context.getBean("postProcessor", ScheduledTaskHolder.class); assertEquals(1, postProcessor.getScheduledTasks().size()); Object target = context.getBean("target"); ScheduledTaskRegistrar registrar = (ScheduledTaskRegistrar) new DirectFieldAccessor(postProcessor).getPropertyValue("registrar"); @SuppressWarnings("unchecked") List<CronTask> cronTasks = (List<CronTask>) new DirectFieldAccessor(registrar).getPropertyValue("cronTasks"); assertEquals(1, cronTasks.size()); CronTask task = cronTasks.get(0); ScheduledMethodRunnable runnable = (ScheduledMethodRunnable) task.getRunnable(); Object targetObject = runnable.getTarget(); Method targetMethod = runnable.getMethod(); assertEquals(target, targetObject); assertEquals("cron", targetMethod.getName()); assertEquals("0 0 0-4,6-23 * * ?", task.getExpression()); Trigger trigger = task.getTrigger(); assertNotNull(trigger); assertTrue(trigger instanceof CronTrigger); CronTrigger cronTrigger = (CronTrigger) trigger; Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+10")); cal.clear(); cal.set(2013, 3, 15, 4, 0); // 15-04-2013 4:00 GMT+10 Date lastScheduledExecutionTime = cal.getTime(); Date lastActualExecutionTime = cal.getTime(); cal.add(Calendar.MINUTE, 30); // 4:30 Date lastCompletionTime = cal.getTime(); TriggerContext triggerContext = new SimpleTriggerContext( lastScheduledExecutionTime, lastActualExecutionTime, lastCompletionTime); cal.add(Calendar.MINUTE, 30); cal.add(Calendar.HOUR_OF_DAY, 1); // 6:00 Date nextExecutionTime = cronTrigger.nextExecutionTime(triggerContext); assertEquals(cal.getTime(), nextExecutionTime); // assert that 6:00 is next execution time }
Example #8
Source File: ScheduledAnnotationBeanPostProcessorTests.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Test public void cronTaskWithZone() throws InterruptedException { Assume.group(TestGroup.LONG_RUNNING); BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class); BeanDefinition targetDefinition = new RootBeanDefinition(CronWithTimezoneTestBean.class); context.registerBeanDefinition("postProcessor", processorDefinition); context.registerBeanDefinition("target", targetDefinition); context.refresh(); Object postProcessor = context.getBean("postProcessor"); Object target = context.getBean("target"); ScheduledTaskRegistrar registrar = (ScheduledTaskRegistrar) new DirectFieldAccessor(postProcessor).getPropertyValue("registrar"); @SuppressWarnings("unchecked") List<CronTask> cronTasks = (List<CronTask>) new DirectFieldAccessor(registrar).getPropertyValue("cronTasks"); assertEquals(1, cronTasks.size()); CronTask task = cronTasks.get(0); ScheduledMethodRunnable runnable = (ScheduledMethodRunnable) task.getRunnable(); Object targetObject = runnable.getTarget(); Method targetMethod = runnable.getMethod(); assertEquals(target, targetObject); assertEquals("cron", targetMethod.getName()); assertEquals("0 0 0-4,6-23 * * ?", task.getExpression()); Trigger trigger = task.getTrigger(); assertNotNull(trigger); assertTrue(trigger instanceof CronTrigger); CronTrigger cronTrigger = (CronTrigger) trigger; Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+10")); cal.clear(); cal.set(2013, 3, 15, 4, 0); // 15-04-2013 4:00 GMT+10 Date lastScheduledExecutionTime = cal.getTime(); Date lastActualExecutionTime = cal.getTime(); cal.add(Calendar.MINUTE, 30); // 4:30 Date lastCompletionTime = cal.getTime(); TriggerContext triggerContext = new SimpleTriggerContext( lastScheduledExecutionTime, lastActualExecutionTime, lastCompletionTime); cal.add(Calendar.MINUTE, 30); cal.add(Calendar.HOUR_OF_DAY, 1); // 6:00 Date nextExecutionTime = cronTrigger.nextExecutionTime(triggerContext); assertEquals(cal.getTime(), nextExecutionTime); // assert that 6:00 is next execution time Thread.sleep(10000); }