1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package com.ebay.carad.os.vitalsigns;
22
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.Iterator;
26 import java.util.List;
27
28 import org.apache.log4j.Logger;
29
30 import com.ebay.carad.os.vitalsigns.listeners.IReportingListener;
31
32 /***
33 * @author Jeremy Thomerson
34 * @version $Id$
35 */
36 public class AbstractListenerContainer implements IReportingListenerContainer {
37
38 private static final Logger LOGGER = Logger.getLogger(AbstractListenerContainer.class);
39
40 private List
41
42 public void setReportingListeners(List listeners) {
43 mReportingListeners.clear();
44 if (listeners != null) {
45 for (Iterator it = listeners.iterator(); it.hasNext(); ) {
46 addReportingListener((IReportingListener) it.next());
47 }
48 }
49 }
50 public void addReportingListener(IReportingListener listener) {
51 if (listener == null) {
52 throw new IllegalArgumentException("listener not allowed to be null");
53 }
54 mReportingListeners.add(listener);
55 }
56
57
58 protected void fireListenersException(IReportingListenerContainer agent, ReportingException re, IDashboardReport rep) {
59 LOGGER.error(re);
60 for (Iterator it = mReportingListeners.iterator(); it.hasNext(); ) {
61 IReportingListener listener = (IReportingListener) it.next();
62 try {
63 listener.reportingException(re, agent, rep);
64 } catch(Exception ex) {
65 LOGGER.error("error firing listeners (reportingException)", ex);
66 }
67 }
68 }
69
70 protected void fireListenersStarted(IDashboardAgent agent) {
71 for (Iterator it = mReportingListeners.iterator(); it.hasNext(); ) {
72 IReportingListener listener = (IReportingListener) it.next();
73 try {
74 listener.reportingPreStart(agent);
75 } catch(Exception ex) {
76 LOGGER.error("error firing listeners (reportingPreStart)", ex);
77 }
78 }
79 }
80
81 protected void fireListenersCompleted(IDashboardAgent agent) {
82 for (Iterator it = mReportingListeners.iterator(); it.hasNext(); ) {
83 IReportingListener listener = (IReportingListener) it.next();
84 try {
85 listener.reportingComplete(agent);
86 } catch(Exception ex) {
87 LOGGER.error("error firing listeners (reportingComplete)", ex);
88 }
89 }
90 }
91
92 protected void fireListenersReportRan(IDashboardAgent agent, IDashboardReport report) {
93 for (Iterator it = mReportingListeners.iterator(); it.hasNext(); ) {
94 IReportingListener listener = (IReportingListener) it.next();
95 try {
96 listener.reportRan(agent, report);
97 } catch(Exception ex) {
98 LOGGER.error("error firing listeners (reportRan)", ex);
99 }
100 }
101 }
102
103 public List getReportingListeners() {
104 return Collections.unmodifiableList(mReportingListeners);
105 }
106 }
107