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