use of org.springframework.scheduling.TriggerContext in project spring-framework by spring-projects.
the class CronTriggerTests method testIncrementDayOfWeekAndRollover.
@Test
public void testIncrementDayOfWeekAndRollover() throws Exception {
CronTrigger trigger = new CronTrigger("* * * * * 2", timeZone);
calendar.set(Calendar.DAY_OF_WEEK, 4);
Date date = calendar.getTime();
calendar.add(Calendar.DAY_OF_MONTH, 6);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
TriggerContext context = getTriggerContext(date);
assertEquals(calendar.getTime(), trigger.nextExecutionTime(context));
assertEquals(Calendar.TUESDAY, calendar.get(Calendar.DAY_OF_WEEK));
}
use of org.springframework.scheduling.TriggerContext in project spring-framework by spring-projects.
the class CronTriggerTests method testIncrementMonthAndRollover.
@Test
public void testIncrementMonthAndRollover() throws Exception {
CronTrigger trigger = new CronTrigger("0 0 0 1 * *", timeZone);
calendar.set(Calendar.MONTH, 11);
calendar.set(Calendar.DAY_OF_MONTH, 31);
calendar.set(Calendar.YEAR, 2010);
Date date = calendar.getTime();
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MONTH, 0);
calendar.set(Calendar.YEAR, 2011);
TriggerContext context1 = getTriggerContext(date);
assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(context1));
calendar.set(Calendar.MONTH, 1);
TriggerContext context2 = getTriggerContext(date);
assertEquals(calendar.getTime(), trigger.nextExecutionTime(context2));
}
use of org.springframework.scheduling.TriggerContext in project uPortal by Jasig.
the class DelegatingThreadPoolTaskScheduler method schedule.
@Override
public ScheduledFuture<Object> schedule(Runnable task, final Trigger trigger) {
task = wrapRunnable(task);
//Wrap the trigger so that the first call to nextExecutionTime adds in the additionalStartDelay
final Trigger wrappedTrigger = new Trigger() {
boolean firstExecution = false;
@Override
public Date nextExecutionTime(TriggerContext triggerContext) {
Date nextExecutionTime = trigger.nextExecutionTime(triggerContext);
if (nextExecutionTime == null) {
return null;
}
if (firstExecution) {
nextExecutionTime = getDelayedStartDate(nextExecutionTime);
firstExecution = true;
}
return nextExecutionTime;
}
};
final DelegatingRunnable delegatingRunnable = new DelegatingRunnable(this.executorService, task);
@SuppressWarnings("unchecked") final ScheduledFuture<ScheduledFuture<Object>> future = super.schedule(delegatingRunnable, wrappedTrigger);
return new DelegatingForwardingScheduledFuture<Object>(future);
}
Aggregations