Search in sources :

Example 26 with Trigger

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

the class QuartzComponent method doAddJob.

private void doAddJob(JobDetail job, Trigger trigger) throws SchedulerException {
    Trigger existingTrigger = getScheduler().getTrigger(trigger.getName(), trigger.getGroup());
    if (existingTrigger == null) {
        LOG.debug("Adding job using trigger: {}/{}", trigger.getGroup(), trigger.getName());
        getScheduler().scheduleJob(job, trigger);
    } else if (hasTriggerChanged(existingTrigger, trigger)) {
        LOG.debug("Trigger: {}/{} already exists and will be updated by Quartz.", trigger.getGroup(), trigger.getName());
        // fast forward start time to now, as we do not want any misfire to kick in
        trigger.setStartTime(new Date());
        // To ensure trigger uses the same job (the job name might change!) we will remove old trigger then re-add.
        scheduler.unscheduleJob(trigger.getName(), trigger.getGroup());
        scheduler.addJob(job, true);
        trigger.setJobName(job.getName());
        trigger.setJobGroup(job.getGroup());
        scheduler.scheduleJob(trigger);
    } else {
        if (!isClustered()) {
            LOG.debug("Trigger: {}/{} already exists and will be resumed by Quartz.", trigger.getGroup(), trigger.getName());
            // fast forward start time to now, as we do not want any misfire to kick in
            trigger.setStartTime(new Date());
            // To ensure trigger uses the same job (the job name might change!) we will remove old trigger then re-add.
            scheduler.unscheduleJob(trigger.getName(), trigger.getGroup());
            scheduler.addJob(job, true);
            trigger.setJobName(job.getName());
            trigger.setJobGroup(job.getGroup());
            scheduler.scheduleJob(trigger);
        } else {
            LOG.debug("Trigger: {}/{} already exists and is already scheduled by clustered JobStore.", trigger.getGroup(), trigger.getName());
        }
    }
    // only increment job counter if we are successful
    incrementJobCounter(getScheduler());
}
Also used : Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) CronTrigger(org.quartz.CronTrigger)

Example 27 with Trigger

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

the class QuartzEndpointConfigureTest method testConfigureName.

@Test
public void testConfigureName() throws Exception {
    QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz://myName");
    Trigger trigger = endpoint.getTrigger();
    assertEquals("getName()", "myName", trigger.getName());
    assertEquals("getGroup()", "Camel", trigger.getGroup());
    // default job name
    assertEquals("getJobName", "quartz-" + endpoint.getId(), endpoint.getJobName());
}
Also used : Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) CronTrigger(org.quartz.CronTrigger) Test(org.junit.Test)

Example 28 with Trigger

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

the class QuartzEndpointConfigureTest method testConfigureNoDoubleSlashNoCron.

@Test
public void testConfigureNoDoubleSlashNoCron() throws Exception {
    QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz:myGroup/myTimerName");
    Trigger trigger = endpoint.getTrigger();
    assertEquals("getName()", "myTimerName", trigger.getName());
    assertEquals("getGroup()", "myGroup", trigger.getGroup());
}
Also used : Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) CronTrigger(org.quartz.CronTrigger) Test(org.junit.Test)

Example 29 with Trigger

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

the class QuartzEndpointConfigureTest method testConfigureGroupAndName.

@Test
public void testConfigureGroupAndName() throws Exception {
    QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz://myGroup/myName?trigger.repeatCount=3");
    Trigger trigger = endpoint.getTrigger();
    assertEquals("getName()", "myName", trigger.getName());
    assertEquals("getGroup()", "myGroup", trigger.getGroup());
    // default job name
    assertEquals("getJobName", "quartz-" + endpoint.getId(), endpoint.getJobName());
    SimpleTrigger simpleTrigger = assertIsInstanceOf(SimpleTrigger.class, trigger);
    assertEquals("getRepeatCount()", 3, simpleTrigger.getRepeatCount());
}
Also used : Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) CronTrigger(org.quartz.CronTrigger) SimpleTrigger(org.quartz.SimpleTrigger) Test(org.junit.Test)

Example 30 with Trigger

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

the class QuartzMessage method populateInitialHeaders.

@Override
protected void populateInitialHeaders(Map<String, Object> map) {
    super.populateInitialHeaders(map);
    if (jobExecutionContext != null) {
        map.put("calendar", jobExecutionContext.getCalendar());
        map.put("fireTime", jobExecutionContext.getFireTime());
        map.put("jobDetail", jobExecutionContext.getJobDetail());
        map.put("jobInstance", jobExecutionContext.getJobInstance());
        map.put("jobRunTime", jobExecutionContext.getJobRunTime());
        map.put("mergedJobDataMap", jobExecutionContext.getMergedJobDataMap());
        map.put("nextFireTime", jobExecutionContext.getNextFireTime());
        map.put("previousFireTime", jobExecutionContext.getPreviousFireTime());
        map.put("refireCount", jobExecutionContext.getRefireCount());
        map.put("result", jobExecutionContext.getResult());
        map.put("scheduledFireTime", jobExecutionContext.getScheduledFireTime());
        map.put("scheduler", jobExecutionContext.getScheduler());
        Trigger trigger = jobExecutionContext.getTrigger();
        map.put("trigger", trigger);
        map.put("triggerName", trigger.getKey().getName());
        map.put("triggerGroup", trigger.getKey().getGroup());
    }
}
Also used : Trigger(org.quartz.Trigger)

Aggregations

Trigger (org.quartz.Trigger)98 JobDetail (org.quartz.JobDetail)47 SchedulerException (org.quartz.SchedulerException)37 CronTrigger (org.quartz.CronTrigger)28 Test (org.junit.Test)23 JobDataMap (org.quartz.JobDataMap)21 Scheduler (org.quartz.Scheduler)21 TriggerKey (org.quartz.TriggerKey)20 SimpleTrigger (org.quartz.SimpleTrigger)19 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)18 JobKey (org.quartz.JobKey)16 ArrayList (java.util.ArrayList)13 Date (java.util.Date)12 List (java.util.List)5 Command (org.openhab.core.types.Command)5 IOException (java.io.IOException)4 InetSocketAddress (java.net.InetSocketAddress)4 SocketChannel (java.nio.channels.SocketChannel)4 ParseException (java.text.ParseException)4 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)4