Skip to content

Instantly share code, notes, and snippets.

@rtrcolin
Created July 16, 2012 07:16
Show Gist options
  • Save rtrcolin/3121315 to your computer and use it in GitHub Desktop.
Save rtrcolin/3121315 to your computer and use it in GitHub Desktop.
Quartz Managed by Dropwizard
public class QuartzManager implements Managed {
private Scheduler scheduler;
private QuartzSchedulerMonitor schedulerMonitor;
private QuartzJobMonitor jobMonitor;
public QuartzManager(SchedulerFactory sf) throws SchedulerException {
scheduler = sf.getScheduler();
schedulerMonitor = new QuartzSchedulerMonitor(); // Implements SchedulerListener
scheduler.getListenerManager().addSchedulerListener(schedulerMonitor);
jobMonitor = new QuartzJobMonitor(); // Implements JobListener
}
@Override
public void start() throws Exception {
scheduler.start();
// Make our Job listener cover all scheduled jobs
scheduler.getListenerManager().addJobListener(jobMonitor, EverythingMatcher.allJobs());
}
@Override
public void stop() throws Exception {
scheduler.getListenerManager().removeJobListener(jobMonitor.getName());
scheduler.shutdown(true);
}
public boolean isHealthy(){
return schedulerMonitor.isHealthy() && jobMonitor.isHealthy();
}
/*
A rudimentary example to get the state of the jobs and scheduler.
*/
public String getState() {
return "Scheduler: " + schedulerMonitor.getState() + " Jobs:" + jobMonitor.getState();
}
...
}
@wulinjie122
Copy link

where is QuartzJobMonitor.java and QuartzSchedulerMonitor.java ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment