View Javadoc

1   // ========================================================================
2   // Copyright (c) Webtide LLC
3   // ------------------------------------------------------------------------
4   // All rights reserved. This program and the accompanying materials
5   // are made available under the terms of the Eclipse Public License v1.0
6   // and Apache License v2.0 which accompanies this distribution.
7   // The Eclipse Public License is available at 
8   // http://www.eclipse.org/legal/epl-v10.html
9   // The Apache License v2.0 is available at
10  // http://www.opensource.org/licenses/apache2.0.php
11  // You may elect to redistribute this code under either of these licenses. 
12  // ========================================================================
13  
14  
15  package org.eclipse.jetty.monitor.jmx;
16  
17  import java.util.Collection;
18  import java.util.Collections;
19  import java.util.HashSet;
20  import java.util.Set;
21  
22  
23  
24  /* ------------------------------------------------------------ */
25  /**
26   * NotifierGroup
27   * 
28   * This class allows for grouping of the event notifiers 
29   */
30  public class NotifierGroup implements EventNotifier
31  {
32      private Set<EventNotifier> _group;
33  
34      /* ------------------------------------------------------------ */
35      /**
36       * Create a notifier group
37       */
38      public NotifierGroup()
39      {
40          _group = new HashSet<EventNotifier>();
41      }
42      
43      /* ------------------------------------------------------------ */
44      /**
45       * Retrieve all event notifier associated with this group
46       * 
47       * @return collection of event notifiers
48       */    
49      public Collection<EventNotifier> getNotifiers()
50      {
51          return Collections.unmodifiableSet(_group);
52      }
53  
54      /* ------------------------------------------------------------ */
55      /**
56       * Add specified event notifier to event notifier group
57       * 
58       * @param notifier event notifier to be added
59       * @return true if successful
60       */
61      public boolean addNotifier(EventNotifier notifier)
62      {
63          return _group.add(notifier);
64      }
65      
66      /* ------------------------------------------------------------ */
67      /**
68       * Add a collection of event notifiers to event notifier group
69       * 
70       * @param notifiers collection of event notifiers to be added
71       * @return true if successful
72       */
73      public boolean addNotifiers(Collection<EventNotifier> notifiers)
74      {
75          return _group.addAll(notifiers);
76      }
77      
78      /* ------------------------------------------------------------ */
79      /**
80       * Remove event notifier from event notifier group
81       * 
82       * @param notifier event notifier to be removed
83       * @return true if successful
84       */
85      public boolean removeNotifier(EventNotifier notifier)
86      {
87          return _group.remove(notifier);
88      }
89   
90      /* ------------------------------------------------------------ */
91      /**
92       * Remove a collection of event notifiers from event notifier group
93       * 
94       * @param notifiers collection of event notifiers to be removed
95       * @return true if successful
96       */
97      public boolean removeNotifiers(Collection<EventNotifier> notifiers)
98      {
99          return _group.removeAll(notifiers);
100     }
101 
102     /* ------------------------------------------------------------ */
103     /**
104      * Invoke the notify() method of each of the notifiers in group
105      * 
106      * @see org.eclipse.jetty.monitor.jmx.EventNotifier#notify(org.eclipse.jetty.monitor.jmx.EventTrigger, org.eclipse.jetty.monitor.jmx.EventState, long)
107      */
108     public void notify(EventTrigger trigger, EventState<?> state, long timestamp)
109     {
110         for (EventNotifier notifier: _group)
111         {
112             notifier.notify(trigger, state, timestamp);
113         }
114     }
115 }