Search in sources :

Example 1 with TriggerKey

use of org.quartz.TriggerKey in project opennms by OpenNMS.

the class ImportScheduler method printCurrentSchedule.

private void printCurrentSchedule() {
    try {
        LOG.info("calendarNames: {}", String.join(", ", getScheduler().getCalendarNames().toArray(new String[0])));
        LOG.info("current executing jobs: {}", StringUtils.arrayToCommaDelimitedString(getScheduler().getCurrentlyExecutingJobs().toArray()));
        LOG.info("current job names: {}", getScheduler().getJobKeys(GroupMatcher.<JobKey>groupEquals(JOB_GROUP)).stream().map(JobKey::getName).collect(Collectors.joining(", ")));
        LOG.info("scheduler metadata: {}", getScheduler().getMetaData());
        LOG.info("trigger names: {}", getScheduler().getTriggerKeys(GroupMatcher.<TriggerKey>groupEquals(JOB_GROUP)).stream().map(TriggerKey::getName).collect(Collectors.joining(", ")));
        for (TriggerKey key : getScheduler().getTriggerKeys(GroupMatcher.<TriggerKey>groupEquals(JOB_GROUP))) {
            String triggerName = key.getName();
            CronTrigger t = (CronTrigger) getScheduler().getTrigger(key);
            LOG.info("trigger: {}, calendar name: {}, cron expression: {}, URL: {}, rescanExisting: {}, next fire time: {}, previous fire time: {}, time zone: {}, priority: {}", triggerName, t.getCalendarName(), t.getCronExpression(), t.getJobDataMap().get(ImportJob.URL), t.getJobDataMap().get(ImportJob.RESCAN_EXISTING), t.getNextFireTime(), t.getPreviousFireTime(), t.getTimeZone(), t.getPriority());
        }
    } catch (Throwable e) {
        LOG.error("printCurrentSchedule: {}", e.getLocalizedMessage(), e);
    }
}
Also used : TriggerKey(org.quartz.TriggerKey) JobKey(org.quartz.JobKey) CronTrigger(org.quartz.CronTrigger)

Example 2 with TriggerKey

use of org.quartz.TriggerKey in project camel by apache.

the class CronScheduledRoutePolicy method createTrigger.

@Override
protected Trigger createTrigger(Action action, Route route) throws Exception {
    Trigger trigger = null;
    CronScheduleBuilder scheduleBuilder = null;
    String triggerPrefix = null;
    if (action == Action.START) {
        scheduleBuilder = CronScheduleBuilder.cronSchedule(getRouteStartTime());
        triggerPrefix = TRIGGER_START;
    } else if (action == Action.STOP) {
        scheduleBuilder = CronScheduleBuilder.cronSchedule(getRouteStopTime());
        triggerPrefix = TRIGGER_STOP;
    } else if (action == Action.SUSPEND) {
        scheduleBuilder = CronScheduleBuilder.cronSchedule(getRouteSuspendTime());
        triggerPrefix = TRIGGER_SUSPEND;
    } else if (action == Action.RESUME) {
        scheduleBuilder = CronScheduleBuilder.cronSchedule(getRouteResumeTime());
        triggerPrefix = TRIGGER_RESUME;
    }
    if (scheduleBuilder != null) {
        if (timeZone != null) {
            scheduleBuilder.inTimeZone(timeZone);
        }
        TriggerKey triggerKey = new TriggerKey(triggerPrefix + route.getId(), TRIGGER_GROUP + route.getId());
        trigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
    }
    return trigger;
}
Also used : TriggerKey(org.quartz.TriggerKey) CronScheduleBuilder(org.quartz.CronScheduleBuilder) Trigger(org.quartz.Trigger)

Example 3 with TriggerKey

use of org.quartz.TriggerKey in project camel by apache.

the class ScheduledRoutePolicy method retrieveTriggerKey.

public TriggerKey retrieveTriggerKey(Action action, String routeId) {
    ScheduledRouteDetails scheduledRouteDetails = getScheduledRouteDetails(routeId);
    TriggerKey result = null;
    if (action == Action.START) {
        result = scheduledRouteDetails.getStartTriggerKey();
    } else if (action == Action.STOP) {
        result = scheduledRouteDetails.getStopTriggerKey();
    } else if (action == Action.SUSPEND) {
        result = scheduledRouteDetails.getSuspendTriggerKey();
    } else if (action == Action.RESUME) {
        result = scheduledRouteDetails.getResumeTriggerKey();
    }
    return result;
}
Also used : TriggerKey(org.quartz.TriggerKey)

Example 4 with TriggerKey

use of org.quartz.TriggerKey in project camel by apache.

the class ScheduledRoutePolicy method pauseRouteTrigger.

public void pauseRouteTrigger(Action action, String routeId) throws SchedulerException {
    TriggerKey triggerKey = retrieveTriggerKey(action, routeId);
    getScheduler().pauseTrigger(triggerKey);
    LOG.debug("Scheduled trigger: {} is paused", triggerKey);
}
Also used : TriggerKey(org.quartz.TriggerKey)

Example 5 with TriggerKey

use of org.quartz.TriggerKey in project camel by apache.

the class QuartzEndpointConfigureTest method testConfigureNoDoubleSlashNoCron.

@Test
public void testConfigureNoDoubleSlashNoCron() throws Exception {
    QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz2:myGroup/myTimerName");
    TriggerKey triggerKey = endpoint.getTriggerKey();
    assertEquals("getName()", "myTimerName", triggerKey.getName());
    assertEquals("getGroup()", "myGroup", triggerKey.getGroup());
}
Also used : TriggerKey(org.quartz.TriggerKey) Test(org.junit.Test)

Aggregations

TriggerKey (org.quartz.TriggerKey)116 Trigger (org.quartz.Trigger)49 SchedulerException (org.quartz.SchedulerException)34 JobKey (org.quartz.JobKey)33 CronTrigger (org.quartz.CronTrigger)25 JobDetail (org.quartz.JobDetail)22 Scheduler (org.quartz.Scheduler)22 Test (org.junit.Test)18 SimpleTrigger (org.quartz.SimpleTrigger)15 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)11 ArrayList (java.util.ArrayList)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 HashMap (java.util.HashMap)9 Date (java.util.Date)6 List (java.util.List)5 CronScheduleBuilder (org.quartz.CronScheduleBuilder)5 BigDecimal (java.math.BigDecimal)4 PreparedStatement (java.sql.PreparedStatement)4 ResultSet (java.sql.ResultSet)4 ParseException (java.text.ParseException)4