View Javadoc

1   /*
2    * $Id: StatusListener.java,v 1.1 2004/03/18 15:23:22 johndavidtaylor Exp $
3    */
4   package org.abraracourcix.alipes.listeners.status;
5   import java.util.Date;
6   import java.util.HashMap;
7   import java.util.Map;
8   import org.abraracourcix.alipes.common.Event;
9   import org.abraracourcix.alipes.listeners.Listener;
10  import org.abraracourcix.alipes.listeners.ListenerException;
11  import org.abraracourcix.alipes.monitors.AbstractMonitor;
12  /***
13   * 
14   * This listener merely retains a list of the latest statuses, and the times
15   * they were received. It will also alert any listeners to the change of state.
16   * @author jdt
17   */
18  public final class StatusListener extends AbstractMonitor implements Listener {
19      /***
20       * @author jdt just a dataholder for the events and date
21       */
22      public final class ResourceInfo {
23          /***
24           * What happened
25           */
26          private Event event;
27          /***
28           * When
29           */
30          private Date date;
31          /***
32           * Constructor
33           * 
34           * @param event
35           *            what
36           * @param date
37           *            when
38           */
39          public ResourceInfo(final Event event, final Date date) {
40              this.event = event;
41              this.date = date;
42          }
43          /***
44           * @return Returns the date.
45           */
46          public Date getDate() {
47              return date;
48          }
49          /***
50           * @return Returns the event.
51           */
52          public Event getEvent() {
53              return event;
54          }
55      }
56      /***
57       * Constructor
58       * 
59       * @param listener
60       *            who's listening?
61       *  
62       */
63      public StatusListener(final Listener listener) {
64          super(listener);
65      }
66      /***
67       * Collection of resources for which we received statuses
68       */
69      private Map statuses = new HashMap();
70      /***
71       * Log the event, and keep a record of it
72       * 
73       * @see org.abraracourcix.alipes.listeners.Listener#eventOccurred(org.abraracourcix.alipes.common.Event,
74       *      java.lang.Object)
75       * @TODO deal with exceptions here properly
76       */
77      public void eventOccurred(final Event event, final Object resource) throws ListenerException {
78          statuses.put(resource, new ResourceInfo(event, new Date()));
79          signalListener(event, resource);
80      }
81      /***
82       * @return Returns the statuses.
83       */
84      public Map getStatuses() {
85          return statuses;
86      }
87  }
88  /*
89   * $Log: StatusListener.java,v $
90   * Revision 1.1  2004/03/18 15:23:22  johndavidtaylor
91   * Copied across from incubation in beanpeeler
92   *
93   * Revision 1.6  2004/03/14 18:49:14  johndavidtaylor
94   * corrected comments
95   *
96   * Revision 1.5  2004/03/14 00:44:22  johndavidtaylor
97   * Added ListenerException
98   *
99   * Revision 1.4  2004/03/11 15:46:35  johndavidtaylor
100  * Applied coding standards
101  * Revision 1.3 2004/03/11 09:49:24
102  * johndavidtaylor Loads of updates
103  * 
104  * Revision 1.2 2004/03/08 20:16:45 johndavidtaylor refactored to new package
105  * name
106  * 
107  * Revision 1.1 2004/03/08 19:58:25 johndavidtaylor Initial commit -transfer
108  * from previous repository
109  * 
110  * Revision 1.1 2004/03/02 23:04:37 jdt new
111  *  
112  */