Translation Quartz.net Framework Tutorial (Chinese Version) 2.2.x seventh lesson trigger listener and Job task listener

Source: Internet
Author: User

Seventh lesson: Triggering listeners and job task listeners

Listeners are objects that perform actions based on the event mechanism in the scheduler. As you can probably guess, the trigger listener receives responses to events related to triggers, and the job task listener receives responses to events related to the job task.

Trigger-related events include: Triggers are triggered, trigger triggers fail (discussed in the trigger course), and trigger triggers are complete (the job task starts running after the trigger completes).

1  Public InterfaceItriggerlistener2 {3      stringName {Get; }4 5      voidtriggerfired (Itrigger trigger, Ijobexecutioncontext context);6 7      BOOLvetojobexecution (Itrigger trigger, Ijobexecutioncontext context);8 9      voidtriggermisfired (Itrigger trigger);Ten  One      voidTriggercomplete (Itrigger trigger, Ijobexecutioncontext context,inttriggerinstructioncode); A}

The events related to the job task include the notification that the job is about to be executed and the notification event that the job execution completes.

The Ijoblistener Interface

1  Public InterfaceIjoblistener2 {3     stringName {Get; }4 5     voidjobtobeexecuted (Ijobexecutioncontext context);6 7     voidjobexecutionvetoed (Ijobexecutioncontext context);8 9     voidjobwasexecuted (ijobexecutioncontext context, jobexecutionexception jobexception);Ten}

Use the listener you have developed


To create a listener, you can simply create an object that implements the Org.quartz.TriggerListener or Org.quartz.JobListener interface. The listener is registered to the scheduler during the run and must be given the listener name (or rather, the listener calls the GetName method to get its own name).

For ease of use, in addition to implementing these interfaces, the listener can also inherit the Itriggerlistener and Ijoblistener classes, and can rewrite only the event methods you are interested in.

When the listener registers to the listener management class in the scheduler, it also carries a match that describes the events that the job task and the listener of the trigger want to receive.

The listener is registered to the schedule during run time, but does not store job tasks and triggers in Jobstore. That's because the listener is usually a collection of points in your app. Therefore, each time the app runs, the listener needs to be re-registered in the scheduler.

To add a job listener to a specified job task:

Scheduler. Listenermanager.addjoblistener (Myjoblistener, Keymatcher<jobkey>. Keyequals (new Jobkey ("myjobname""myjobgroup")));

Add a job listener to all job tasks in one of the job groups you are interested in:

Scheduler. Listenermanager.addjoblistener (Myjoblistener, Groupmatcher<jobkey>. Groupequals ("myjobgroup"));


Add a job listener to all the job tasks in the two job groups that you are interested in:
Scheduler. Listenermanager.addjoblistener (Myjoblistener,

Ormatcher<jobkey>. Or (GROUPMATCHER<JOBKEY>. Groupequals ("myjobgroup"), Groupmatcher<jobkey>. Groupequals ("yourgroup"));


To add a job listener to all jobs:

1 Scheduler. Listenermanager.addjoblistener (Myjoblistener, Groupmatcher<jobkey>. Anygroup ());

Registering the trigger listener also uses the same method.

The listener is not used by most quartz users, but it is very convenient to use the listener when the app requires that you create the required event notifications without the job instance notifying the app.




Translation Quartz.net Framework Tutorial (Chinese Version) 2.2.x seventh lesson trigger listener and Job task listener

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.