private void createAndInitScheduler() throws SchedulerException {
LOG.info("Create and initializing scheduler.");
scheduler = createScheduler();
// Store CamelContext into QuartzContext space
SchedulerContext quartzContext = scheduler.getContext();
String camelContextName = QuartzHelper.getQuartzContextName(getCamelContext());
LOG.debug("Storing camelContextName={} into Quartz Context space.", camelContextName);
quartzContext.put(QuartzConstants.QUARTZ_CAMEL_CONTEXT + "-" + camelContextName, getCamelContext());
// Set camel job counts to zero. We needed this to prevent shutdown in case there are multiple Camel contexts
// that has not completed yet, and the last one with job counts to zero will eventually shutdown.
AtomicInteger number = (AtomicInteger) quartzContext.get(QuartzConstants.QUARTZ_CAMEL_JOBS_COUNT);
if (number == null) {
number = new AtomicInteger(0);
quartzContext.put(QuartzConstants.QUARTZ_CAMEL_JOBS_COUNT, number);
}
}