use of org.pentaho.platform.api.scheduler2.IBlockoutManager in project pentaho-platform by pentaho.
the class BlockoutManagerUtil method getFireTimes.
public static List<Date> getFireTimes(IJobTrigger jobTrigger, IScheduler scheduler) {
// Determines the maximum amount of fire times allowed to be calculated
int n = 1000;
Date startDate = new Date(System.currentTimeMillis());
Date endDate = new Date(startDate.getTime() + 4 * TIME.YEAR.time);
// Quartz Triggers
if (scheduler instanceof QuartzScheduler) {
try {
List<Date> dates = new ArrayList<Date>();
boolean endDateIsNull = jobTrigger.getEndTime() == null;
// $NON-NLS-1$ //$NON-NLS-2$
Trigger trigger = QuartzScheduler.createQuartzTrigger(jobTrigger, new QuartzJobKey("test", "test"));
// add previous trigger (it might be currently active)
// $NON-NLS-1$;
IBlockoutManager manager = PentahoSystem.get(IBlockoutManager.class, "IBlockoutManager", null);
if (manager != null) {
List<Job> blockouts = manager.getBlockOutJobs();
for (Job blockout : blockouts) {
if (blockout.getLastRun() != null) {
dates.add(blockout.getLastRun());
}
}
}
for (int i = 0; i < n; i++) {
Date nextFireTime = trigger.getFireTimeAfter(startDate);
if ((nextFireTime == null) || (nextFireTime.after(endDate) || (!endDateIsNull && nextFireTime.after(jobTrigger.getEndTime())))) {
break;
}
dates.add(nextFireTime);
startDate = nextFireTime;
}
return dates;
} catch (SchedulerException e) {
throw new RuntimeException(e);
}
}
throw new RuntimeException(// $NON-NLS-1$
"Can not calculate fire times for unsupported Scheduler Type: " + scheduler.getClass().getSimpleName());
}
Aggregations