Search in sources :

Example 1 with IBlockoutManager

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());
}
Also used : SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) QuartzJobKey(org.pentaho.platform.scheduler2.quartz.QuartzJobKey) ArrayList(java.util.ArrayList) QuartzScheduler(org.pentaho.platform.scheduler2.quartz.QuartzScheduler) Date(java.util.Date) CronJobTrigger(org.pentaho.platform.api.scheduler2.CronJobTrigger) SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) Trigger(org.quartz.Trigger) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) Job(org.pentaho.platform.api.scheduler2.Job) IBlockoutManager(org.pentaho.platform.api.scheduler2.IBlockoutManager)

Aggregations

ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)1 CronJobTrigger (org.pentaho.platform.api.scheduler2.CronJobTrigger)1 IBlockoutManager (org.pentaho.platform.api.scheduler2.IBlockoutManager)1 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)1 Job (org.pentaho.platform.api.scheduler2.Job)1 SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)1 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)1 QuartzJobKey (org.pentaho.platform.scheduler2.quartz.QuartzJobKey)1 QuartzScheduler (org.pentaho.platform.scheduler2.quartz.QuartzScheduler)1 Trigger (org.quartz.Trigger)1