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