首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Lesson 七: TriggerListeners and c

2012-10-27 
Lesson 7: TriggerListeners and cQuartz Enterprise Job Scheduler TutorialLesson 7: TriggerListeners

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).

Listeners are registered with the scheduler during run time, and are NOT stored in the JobStore along with the jobs and triggers. This is because listeners are typically an integration point with your application. Hence, each time your application runs, the listeners need to be re-registered with the scheduler.
Adding a JobListener that is interested in a particular job:
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")));
Adding a JobListener that is interested in all jobs of a particular group:
scheduler.getListenerManager().addJobListener(myJobListener, groupEquals("myJobGroup"));
Adding a JobListener that is interested in all jobs of two particular groups:
scheduler.getListenerManager().addJobListener(myJobListener, or(groupEquals("myJobGroup"), groupEquals("yourGroup")));
Adding a JobListener that is interested in all jobs:
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.

热点排行