Only stop the scheduler once it is set.

Original commit: elastic/x-pack-elasticsearch@4238a62673
This commit is contained in:
Martijn van Groningen 2014-11-20 14:44:12 +01:00
parent 306fefd847
commit e3694655af
1 changed files with 10 additions and 5 deletions

View File

@ -27,8 +27,8 @@ public class AlertScheduler extends AbstractComponent {
// Not happy about it, but otherwise we're stuck with Quartz's SimpleThreadPool
private volatile static ThreadPool threadPool;
private volatile Scheduler scheduler;
private AlertManager alertManager;
private volatile Scheduler scheduler;
@Inject
public AlertScheduler(Settings settings, ThreadPool threadPool) {
@ -56,9 +56,10 @@ public class AlertScheduler extends AbstractComponent {
properties.setProperty(StdSchedulerFactory.PROP_SCHED_INTERRUPT_JOBS_ON_SHUTDOWN, "true");
properties.setProperty(StdSchedulerFactory.PROP_SCHED_INTERRUPT_JOBS_ON_SHUTDOWN_WITH_WAIT, "true");
SchedulerFactory schFactory = new StdSchedulerFactory(properties);
scheduler = schFactory.getScheduler();
Scheduler scheduler = schFactory.getScheduler();
scheduler.setJobFactory(new SimpleJobFactory());
scheduler.start();
this.scheduler = scheduler;
for (Map.Entry<String, Alert> entry : alerts.entrySet()) {
add(entry.getKey(), entry.getValue());
}
@ -72,9 +73,13 @@ public class AlertScheduler extends AbstractComponent {
*/
public synchronized void stop() {
try {
scheduler.clear();
scheduler.shutdown(true);
logger.info("Stopped scheduler");
if (scheduler != null) {
logger.info("Stopping scheduler...");
scheduler.clear();
scheduler.shutdown(true);
scheduler = null;
logger.info("Stopped scheduler");
}
} catch (SchedulerException se){
logger.error("Failed to stop quartz scheduler", se);
}