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());
}
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());
}
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());
}
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());
}
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());
}
}
Aggregations