use of org.quartz.CronTrigger in project camel by apache.
the class QuartzComponent method createCronTrigger.
protected CronTrigger createCronTrigger(String path) throws ParseException {
CronTrigger cron = new CronTrigger();
cron.setCronExpression(path);
return cron;
}
use of org.quartz.CronTrigger in project camel by apache.
the class QuartzEndpointConfigureTest method testConfigureAnotherCronExpression.
@Test
public void testConfigureAnotherCronExpression() throws Exception {
QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz://myGroup/myTimerName?cron=0+0+*+*+*+?");
CronTrigger trigger = assertIsInstanceOf(CronTrigger.class, endpoint.getTrigger());
assertEquals("getName()", "myTimerName", trigger.getName());
assertEquals("getGroup()", "myGroup", trigger.getGroup());
assertEquals("cron expression", "0 0 * * * ?", trigger.getCronExpression());
// default job name
assertEquals("getJobName", "quartz-" + endpoint.getId(), endpoint.getJobName());
}
use of org.quartz.CronTrigger in project camel by apache.
the class QuartzEndpointConfigureTest method testConfigureJobName.
@Test
public void testConfigureJobName() throws Exception {
QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz://myGroup/myTimerName?job.name=hadrian&cron=0+0+*+*+*+?");
CronTrigger trigger = assertIsInstanceOf(CronTrigger.class, endpoint.getTrigger());
assertEquals("getName()", "myTimerName", trigger.getName());
assertEquals("getGroup()", "myGroup", trigger.getGroup());
assertEquals("cron expression", "0 0 * * * ?", trigger.getCronExpression());
assertEquals("getJobName", "hadrian", endpoint.getJobName());
}
use of org.quartz.CronTrigger in project camel by apache.
the class QuartzEndpointConfigureTest method testConfigureNoDoubleSlashQuestionCron.
@Test
public void testConfigureNoDoubleSlashQuestionCron() throws Exception {
QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz:myGroup/myTimerName?cron=0+0+*+*+*+?");
CronTrigger trigger = assertIsInstanceOf(CronTrigger.class, endpoint.getTrigger());
assertEquals("getName()", "myTimerName", trigger.getName());
assertEquals("getGroup()", "myGroup", trigger.getGroup());
assertEquals("cron expression", "0 0 * * * ?", trigger.getCronExpression());
}
use of org.quartz.CronTrigger in project camel by apache.
the class QuartzEndpoint method createTrigger.
private Trigger createTrigger(JobDetail jobDetail) throws Exception {
Trigger result;
Date startTime = new Date();
if (getComponent().getScheduler().isStarted()) {
startTime = new Date(System.currentTimeMillis() + triggerStartDelay);
}
if (cron != null) {
LOG.debug("Creating CronTrigger: {}", cron);
String timeZone = (String) triggerParameters.get("timeZone");
if (timeZone != null) {
if (ObjectHelper.isNotEmpty(customCalendar)) {
result = TriggerBuilder.newTrigger().withIdentity(triggerKey).startAt(startTime).withSchedule(cronSchedule(cron).withMisfireHandlingInstructionFireAndProceed().inTimeZone(TimeZone.getTimeZone(timeZone))).modifiedByCalendar(QuartzConstants.QUARTZ_CAMEL_CUSTOM_CALENDAR).build();
} else {
result = TriggerBuilder.newTrigger().withIdentity(triggerKey).startAt(startTime).withSchedule(cronSchedule(cron).withMisfireHandlingInstructionFireAndProceed().inTimeZone(TimeZone.getTimeZone(timeZone))).build();
}
jobDetail.getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_CRON_TIMEZONE, timeZone);
} else {
if (ObjectHelper.isNotEmpty(customCalendar)) {
result = TriggerBuilder.newTrigger().withIdentity(triggerKey).startAt(startTime).withSchedule(cronSchedule(cron).withMisfireHandlingInstructionFireAndProceed()).modifiedByCalendar(QuartzConstants.QUARTZ_CAMEL_CUSTOM_CALENDAR).build();
} else {
result = TriggerBuilder.newTrigger().withIdentity(triggerKey).startAt(startTime).withSchedule(cronSchedule(cron).withMisfireHandlingInstructionFireAndProceed()).build();
}
}
// enrich job map with details
jobDetail.getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_TYPE, "cron");
jobDetail.getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_CRON_EXPRESSION, cron);
} else {
LOG.debug("Creating SimpleTrigger.");
int repeat = SimpleTrigger.REPEAT_INDEFINITELY;
String repeatString = (String) triggerParameters.get("repeatCount");
if (repeatString != null) {
repeat = EndpointHelper.resolveParameter(getCamelContext(), repeatString, Integer.class);
// need to update the parameters
triggerParameters.put("repeatCount", repeat);
}
// default use 1 sec interval
long interval = 1000;
String intervalString = (String) triggerParameters.get("repeatInterval");
if (intervalString != null) {
interval = EndpointHelper.resolveParameter(getCamelContext(), intervalString, Long.class);
// need to update the parameters
triggerParameters.put("repeatInterval", interval);
}
TriggerBuilder<SimpleTrigger> triggerBuilder;
if (ObjectHelper.isNotEmpty(customCalendar)) {
triggerBuilder = TriggerBuilder.newTrigger().withIdentity(triggerKey).startAt(startTime).withSchedule(simpleSchedule().withMisfireHandlingInstructionFireNow().withRepeatCount(repeat).withIntervalInMilliseconds(interval)).modifiedByCalendar(QuartzConstants.QUARTZ_CAMEL_CUSTOM_CALENDAR);
} else {
triggerBuilder = TriggerBuilder.newTrigger().withIdentity(triggerKey).startAt(startTime).withSchedule(simpleSchedule().withMisfireHandlingInstructionFireNow().withRepeatCount(repeat).withIntervalInMilliseconds(interval));
}
if (fireNow) {
triggerBuilder = triggerBuilder.startNow();
}
result = triggerBuilder.build();
// enrich job map with details
jobDetail.getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_TYPE, "simple");
jobDetail.getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_SIMPLE_REPEAT_COUNTER, repeat);
jobDetail.getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_SIMPLE_REPEAT_INTERVAL, interval);
}
if (triggerParameters != null && triggerParameters.size() > 0) {
LOG.debug("Setting user extra triggerParameters {}", triggerParameters);
setProperties(result, triggerParameters);
}
LOG.debug("Created trigger={}", result);
return result;
}
Aggregations