Lesson 7: TriggerListeners and JobListeners   Leave a comment

Listeners are objects that you create to perform actions based on
events occuring 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 the implements either
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. Listeners can be registered as either "global"
or "non-global". Global listeners receive events for ALL triggers/jobs,
and non-global listeners receive events only for the specific
triggers/jobs that explicitely name the listener in their
getTriggerListenerNames() or getJobListenerNames() properties.

As described above, listeners are registered with the scheduler
during run time, and are NOT stored in the JobStore along with the jobs
and triggers. The jobs and triggers only have the names of the related
listeners stored with them. Hence, each time your application runs, the
listeners need to be re-registered with the scheduler.

Adding a JobListener to the Scheduler



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 explicitly notifying the application.


Posted 2009年11月3日 by gw8310 in Computers and Internet


Fill in your details below or click an icon to log in:

WordPress.com 徽标

You are commenting using your WordPress.com account. Log Out /  更改 )

Google+ photo

You are commenting using your Google+ account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )


Connecting to %s

%d 博主赞过: