KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quartz > listeners > BroadcastSchedulerListener


1 package org.quartz.listeners;
2
3 import java.util.Iterator JavaDoc;
4 import java.util.LinkedList JavaDoc;
5 import java.util.List JavaDoc;
6
7 import org.quartz.SchedulerException;
8 import org.quartz.SchedulerListener;
9 import org.quartz.Trigger;
10
11 /**
12  * Holds a List of references to SchedulerListener instances and broadcasts all
13  * events to them (in order).
14  *
15  * <p>This may be more convenient than registering all of the listeners
16  * directly with the Scheduler, and provides the flexibility of easily changing
17  * which listeners get notified.</p>
18  *
19  * @see #addListener(org.quartz.SchedulerListener)
20  * @see #removeListener(org.quartz.SchedulerListener)
21  *
22  * @author James House (jhouse AT revolition DOT net)
23  */

24 public class BroadcastSchedulerListener implements SchedulerListener {
25
26     private List JavaDoc listeners;
27
28     public BroadcastSchedulerListener() {
29         listeners = new LinkedList JavaDoc();
30     }
31
32     /**
33      * Construct an instance with the given List of listeners.
34      *
35      * @param listeners the initial List of SchedulerListeners to broadcast to.
36      */

37     public BroadcastSchedulerListener(List JavaDoc listeners) {
38         this();
39         this.listeners.addAll(listeners);
40     }
41
42
43     public void addListener(SchedulerListener listener) {
44         listeners.add(listener);
45     }
46
47     public boolean removeListener(SchedulerListener listener) {
48         return listeners.remove(listener);
49     }
50
51     public List JavaDoc getListeners() {
52         return java.util.Collections.unmodifiableList(listeners);
53     }
54
55     public void jobScheduled(Trigger trigger) {
56         Iterator JavaDoc itr = listeners.iterator();
57         while(itr.hasNext()) {
58             SchedulerListener l = (SchedulerListener) itr.next();
59             l.jobScheduled(trigger);
60         }
61     }
62
63     public void jobUnscheduled(String JavaDoc triggerName, String JavaDoc triggerGroup) {
64         Iterator JavaDoc itr = listeners.iterator();
65         while(itr.hasNext()) {
66             SchedulerListener l = (SchedulerListener) itr.next();
67             l.jobUnscheduled(triggerName, triggerGroup);
68         }
69     }
70
71     public void triggerFinalized(Trigger trigger) {
72         Iterator JavaDoc itr = listeners.iterator();
73         while(itr.hasNext()) {
74             SchedulerListener l = (SchedulerListener) itr.next();
75             l.triggerFinalized(trigger);
76         }
77     }
78
79     public void triggersPaused(String JavaDoc triggerName, String JavaDoc triggerGroup) {
80         Iterator JavaDoc itr = listeners.iterator();
81         while(itr.hasNext()) {
82             SchedulerListener l = (SchedulerListener) itr.next();
83             l.triggersPaused(triggerName, triggerGroup);
84         }
85     }
86
87     public void triggersResumed(String JavaDoc triggerName, String JavaDoc triggerGroup) {
88         Iterator JavaDoc itr = listeners.iterator();
89         while(itr.hasNext()) {
90             SchedulerListener l = (SchedulerListener) itr.next();
91             l.triggersResumed(triggerName, triggerGroup);
92         }
93     }
94
95     public void jobsPaused(String JavaDoc jobName, String JavaDoc jobGroup) {
96         Iterator JavaDoc itr = listeners.iterator();
97         while(itr.hasNext()) {
98             SchedulerListener l = (SchedulerListener) itr.next();
99             l.jobsPaused(jobName, jobGroup);
100         }
101     }
102
103     public void jobsResumed(String JavaDoc jobName, String JavaDoc jobGroup) {
104         Iterator JavaDoc itr = listeners.iterator();
105         while(itr.hasNext()) {
106             SchedulerListener l = (SchedulerListener) itr.next();
107             l.jobsResumed(jobName, jobGroup);
108         }
109     }
110
111     public void schedulerError(String JavaDoc msg, SchedulerException cause) {
112         Iterator JavaDoc itr = listeners.iterator();
113         while(itr.hasNext()) {
114             SchedulerListener l = (SchedulerListener) itr.next();
115             l.schedulerError(msg, cause);
116         }
117     }
118
119     public void schedulerShutdown() {
120         Iterator JavaDoc itr = listeners.iterator();
121         while(itr.hasNext()) {
122             SchedulerListener l = (SchedulerListener) itr.next();
123             l.schedulerShutdown();
124         }
125     }
126 }
127
Popular Tags