Lesson 7: TriggerListeners and c
Quartz Enterprise Job Scheduler TutorialLesson 7: TriggerListeners and JobListeners
Listeners are objects that you create to perform actions based on events occurring within the scheduler. As youcan probably guess, TriggerListeners receive events related to triggers, and JobListenersreceive events related to jobs.
Trigger-related events include: trigger firings, trigger mis-firings (discussed in the "Triggers" section of thisdocument), and trigger completions (the jobs fired off by the trigger is finished).
scheduler.getListenerManager().addJobListener(myJobListener, KeyMatcher.keyEquals(new JobKey("myJobName", "myJobGroup")));You may want to use static imports for the matcher and key classes, which will make your defining the matchers cleaner:
import static org.quartz.JobKey.*;import static org.quartz.impl.matchers.KeyMatcher.*;import static org.quartz.impl.matchers.GroupMatcher.*;import static org.quartz.impl.matchers.AndMatcher.*;import static org.quartz.impl.matchers.OrMatcher.*;import static org.quartz.impl.matchers.EverythingMatcher.*;...etc.
Which turns the above example into this:
scheduler.getListenerManager().addJobListener(myJobListener, keyEquals(jobKey("myJobName", "myJobGroup")));scheduler.getListenerManager().addJobListener(myJobListener, groupEquals("myJobGroup"));scheduler.getListenerManager().addJobListener(myJobListener, or(groupEquals("myJobGroup"), groupEquals("yourGroup")));scheduler.getListenerManager().addJobListener(myJobListener, allJobs());
...Registering TriggerListeners works in just the same way.
Listeners are not used by most users of Quartz, but are handy when application requirements create the need forthe notification of events, without the Job itself having to explicitly notify the application.