}
private void doAddJob(JobDetail job, Trigger trigger) throws SchedulerException {
jobs.incrementAndGet();
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());
// replace job, and relate trigger to previous job name, which is needed to reschedule job
scheduler.addJob(job, true);
trigger.setJobName(existingTrigger.getJobName());
scheduler.rescheduleJob(trigger.getName(), trigger.getGroup(), 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());
// replace job, and relate trigger to previous job name, which is needed to reschedule job
scheduler.addJob(job, true);
trigger.setJobName(existingTrigger.getJobName());
scheduler.rescheduleJob(trigger.getName(), trigger.getGroup(), trigger);
} else {
LOG.debug("Trigger: {}/{} already exists and is already scheduled by clustered JobStore.", trigger.getGroup(), trigger.getName());
}
}