}
Map<String, Object> triggerParameters = IntrospectionSupport.extractProperties(parameters, "trigger.");
Map<String, Object> jobParameters = IntrospectionSupport.extractProperties(parameters, "job.");
Trigger trigger;
boolean stateful = "true".equals(parameters.get("stateful"));
// if we're starting up and not running in Quartz clustered mode or not stateful then check for a name conflict.
if (!isClustered() && !stateful) {
// check to see if this trigger already exists
trigger = getScheduler().getTrigger(name, group);
if (trigger != null) {
String msg = "A Quartz job already exists with the name/group: " + name + "/" + group;
throw new IllegalArgumentException(msg);
}
}
// create the trigger either cron or simple
if (ObjectHelper.isNotEmpty(cron)) {
cron = encodeCronExpression(cron);
trigger = createCronTrigger(cron);
} else {
trigger = new SimpleTrigger();
if (fireNow) {
String intervalString = (String) triggerParameters.get("repeatInterval");
if (intervalString != null) {
long interval = Long.valueOf(intervalString);
trigger.setStartTime(new Date(System.currentTimeMillis() - interval));
}
}
}
QuartzEndpoint answer = new QuartzEndpoint(uri, this);
setProperties(answer.getJobDetail(), jobParameters);
// enrich job data map with trigger information
if (cron != null) {
answer.getJobDetail().getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_TYPE, "cron");
answer.getJobDetail().getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_CRON_EXPRESSION, cron);
} else {
answer.getJobDetail().getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_TYPE, "simple");
Long interval = getCamelContext().getTypeConverter().convertTo(Long.class, triggerParameters.get("repeatInterval"));
if (interval != null) {
answer.getJobDetail().getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_SIMPLE_REPEAT_INTERVAL, interval);
}
Integer counter = getCamelContext().getTypeConverter().convertTo(Integer.class, triggerParameters.get("repeatCount"));
if (counter != null) {
answer.getJobDetail().getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_SIMPLE_REPEAT_COUNTER, counter);
}
}
setProperties(trigger, triggerParameters);
trigger.setName(name);
trigger.setGroup(group);
answer.setTrigger(trigger);
return answer;
}