View Javadoc

1   /*
2    * The contents of this file are subject to the terms 
3    * of the Common Development and Distribution License 
4    * (the "License").  You may not use this file except 
5    * in compliance with the License.
6    * 
7    * You can obtain a copy of the license at 
8    * http://www.sun.com/cddl/cddl.html. 
9    * See the License for the specific language governing 
10   * permissions and limitations under the License.
11   * 
12   * When distributing Covered Code, include this CDDL 
13   * HEADER in each file and include the License file at 
14   * license.txt.  If applicable, add the following below 
15   * this CDDL HEADER, with the fields enclosed by brackets 
16   * "[]" replaced with your own identifying information: 
17   * Portions Copyright [yyyy] [name of copyright owner]
18   * 
19   * Portions Copyright 2004 eBay, Inc.
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 /*<IReportingListener>*/ mReportingListeners = new ArrayList();
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      /* Listeners methods */
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