Chapter 7. Implementing Quartz Listeners
Listeners provide a
|
Listeners as Extension Points
The phrase
extension point
is used in software development to
Quartz listeners are a type of extension point in which you, as a Quartz
Listeners are not the only extension points in the framework. Along with plug-ins and a few other customization options, listeners provide a simple means of customizing the framework and making it do what you need it to do. Because the extension points for listeners are supported through a publicized interface, you don't have to worry about creating your own branch of the code that then is unsupportable. |
Implementing a Listener
In the discussion that
Creating the Listener ClassThe listener is a Java interface and must be implemented by a concrete class. The class doesn't have to be a specialized class created just for this purpose; it can be any Java class that you want to receive the callback methods on. In keeping with good program design, you should be careful to keep tight cohesion but loose coupling. Seriously consider which class you decide to implement the listener with; this is important from an overall design perspective. Implementing the Listener MethodsBecause listeners are ordinary Java interfaces, every method must be implemented in your listener implementation class. If there are any methods in the listener interface that you are not interested in, you are allowed to have an empty body for the method; however, you still must provide a valid method implementation of it. For example, the following code snippet shows an empty method body for one of the
SchedulerListener methods:
... rest of the SchedulerListener not shown
public void schedulerShutdown(){
// Don't care about the shutdown event
}
Registering the ListenerTo receive the callback methods, the Scheduler must be aware of the listener instance. Figure 7.1 illustrates the process of registering a listener with the Scheduler and receiving the callbacks. Figure 7.1. Listeners are registered with and receive callbacks from the Scheduler.
Global vs. Nonglobal ListenersThe JobListener and triggerListener can be registered as either a global or nonglobal listener. A global listener is one that receives event notifications for all jobs/triggers. A nonglobal listener (or just a standard listener) receives event notifications for only those jobs or triggers that have registered listeners on them. Whether you register your listener as a global or nonglobal listener depends on your specific application needs. We provide examples of both ways in the following sections. Another way to look at global and nonglobal listeners comes from the creator of the Quartz framework. James House describes global and nonglobal listeners this way:
|