`
thinktothings
  • 浏览: 780217 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Lesson 7: TriggerListeners and c

阅读更多

Quartz Enterprise Job Scheduler Tutorial

Lesson 7: TriggerListeners and JobListeners

Listeners are objects that you create to perform actions based on events occurring within the scheduler. As you can probably guess, TriggerListeners receive events related to triggers, and JobListeners receive events related to jobs.

Trigger-related events include: trigger firings, trigger mis-firings (discussed in the "Triggers" section of this document), and trigger completions (the jobs fired off by the trigger is finished).

The org.quartz.TriggerListener Interface
public interface TriggerListener {

    public String getName();

    public void triggerFired(Trigger trigger, JobExecutionContext context);

    public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context);

    public void triggerMisfired(Trigger trigger);

    public void triggerComplete(Trigger trigger, JobExecutionContext context,
            int triggerInstructionCode);
}

Job-related events include: a notification that the job is about to be executed, and a notification when the job has completed execution.

The org.quartz.JobListener Interface
public interface JobListener {

    public String getName();

    public void jobToBeExecuted(JobExecutionContext context);

    public void jobExecutionVetoed(JobExecutionContext context);

    public void jobWasExecuted(JobExecutionContext context,
            JobExecutionException jobException);

}

Using Your Own Listeners

To create a listener, simply create an object that implements the org.quartz.TriggerListener and/or org.quartz.JobListener interface. Listeners are then registered with the scheduler during run time, and must be given a name (or rather, they must advertise their own name via their getName() method).

For your convenience, tather than implementing those interfaces, your class could also extend the class JobListenerSupport or TriggerListenerSupport and simply override the events you're interested in.

Listeners are registered with the scheduler's ListenerManager along with a Matcher that describes which Jobs/Triggers the listener wants to receive events for.

Info 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 for the notification of events, without the Job itself having to explicitly notify the application.

分享到:
评论

相关推荐

    Lesson01:课程概述与如何学好FPGA

    Lesson01:课程概述与如何学好FPGA

    ELLIOTT WAVE PRINCIPLE

    Lesson 7: Flats (3-3-5) - 32 - Lesson 8: Triangles - 36 - Lesson 9: Corrective Combinations - 39 - Lesson 10: The guideline of alternation - 43 - Lesson 11: Forecasting corrective waves - 46 - Lesson ...

    画法几何课件:第七讲 相交问题 Lesson 7: Intersections.ppt

    画法几何课件:第七讲 相交问题 Lesson 7: Intersections.ppt

    Verigy HP93K Port_scale_RF_Taining_slide_sets(RF)

    Lesson 7: Control RF Triggering Lesson 8: Review Sampling Parameters Lesson 9: Measure Intermodulation Distortion (RF to RF) Lesson 10: Measure Intermodulation Distortion (RF to RF) Lesson 11: ...

    Lesson27:Danny+at+home课件.ppt

    Lesson27:Danny+at+home课件.ppt

    Lesson 3: More About Jobs and Job Details

    "Lesson 3: More About Jobs and Job Details"这个主题聚焦于如何更深入地理解任务(Jobs)以及它们的相关细节。在这个教程中,我们将探讨任务管理的核心概念、相关的工具,以及如何通过源码分析来了解其工作原理。 ...

    Lesson 4: More About Triggers

    本课"Lesson 4: More About Triggers"深入探讨了触发器的使用和实现细节。 在关系型数据库中,触发器主要用于实现数据完整性、业务规则的强制和审计跟踪等功能。当数据发生变化时,它们可以执行复杂的操作,这些...

    s4f00 Overview of Financials in SAP S/4HANA 2018英文版 PDF

    1Unit1:SAP S/4HANA Finance-Introduction and ...75Lesson:Posting and Analyzing in Accounts Receivable 91 Unit 5:Understanding the Central Finance Option 92Lesson:Understanding the Central Finance Option

    Maya Lesson 1: Modeling a polygonal mesh from a reference image

    Lesson 1: Modeling a polygonal mesh from a reference image 导入两张图片,用多边形画头盔

    《Node.js包教不包会》.zip

    Lesson 7: 《浏览器端测试:mocha,chai,phantomjs》 -- by @elrrrrrrr Lesson 8: 《测试用例:supertest》 Lesson 9: 《正则表达式》 Lesson 10: 《benchmark 怎么写》 Lesson 11: 《作用域与闭包:this,var...

    Adobe Illustrator CS6 Digital Classroom

    Lesson 7: Working with and Formatting Text Lesson 8: Organizing your Illustrations with Layers Lesson 9: Working with Symbols Lesson 10: Using Effects and Transparency Lesson 11: Exporting and ...

    opengl.rar_OPENGL NE_nehe lesson_opengl nehe

    7. Lesson7:视口和投影 - 学习如何调整视口大小和投影模式,以适应不同的显示需求。 8. Lesson8:动画 - 涉及如何通过帧间变化创建动态效果,比如旋转、平滑移动等。 9. Lesson9:键盘和鼠标输入 - 讲解如何处理...

    fastai 2019 lesson1~lesson12中文笔记.zip

    Lesson7:文本数据处理 详细介绍了如何处理和准备文本数据,包括分词、词汇表构建以及张量化的技巧。还介绍了TextDataBunch,它是fastai库中用于处理文本数据的工具。 Lesson8:文本分类 这节课讲解了如何使用预...

    Lesson16:HappyorSad.pptx

    这篇资料是关于Lesson16的课程,主题是“Happy or Sad”,主要教授孩子们理解和表达不同的情绪。课程通过对话和互动活动来帮助孩子们学习如何描述自己的情绪,并培养他们的情感认知。 首先,课程中出现了两个角色,...

    IMPROVEYOURMATH.pdf

    - **Lesson7: Adding and Subtracting Decimals 加减小数** - **对齐小数点**: 确保所有数的小数点对齐后再进行加减运算。 - **Lesson8: Multiplying and Dividing Decimals 乘除小数** - **乘法**: 先忽略小数点...

    二年级英语下册Unit1_2活动手册素材pdf冀教版一起

    * Lesson 4:Washroom and Library,介绍学校的基础设施,包括洗手间和图书馆。 * Lesson 5:Gym and Playground,介绍学校的体育设施,包括体育馆和游乐场。 * Lesson 6:Open and Close,教授学生打开和关闭的动作...

    水利水电工程专业英语教材.doc

    Lesson 7:水资源开发规划 水资源开发规划是指为满足人类对水资源的需求,制定的一系列计划和措施。水资源开发规划的目的是为了合理利用水资源,确保水资源的可持续发展。 Lesson 8:水库 水库是指人工建立...

Global site tag (gtag.js) - Google Analytics