01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.tomcat.util.modeler;
19:
20: import java.util.HashSet;
21:
22: import javax.management.Notification;
23: import javax.management.NotificationFilter;
24:
25: /**
26: * Special NotificationFilter that allows modeler to optimize its notifications.
27: *
28: * This class is immutable - after you construct it it'll filter based on
29: * a fixed set of notification names.
30: *
31: * The JMX specification requires the filters to be called before the
32: * notifications are sent. We can call this filter well in advance, when
33: * the listener is added. Based on the result we can maintain separate
34: * channels for each notification - and reduce the overhead.
35: *
36: * @author Costin Manolache
37: */
38: public class FixedNotificationFilter implements NotificationFilter {
39:
40: /**
41: * The set of attribute names that are accepted by this filter. If this
42: * list is empty, all attribute names are accepted.
43: */
44: private HashSet names = new HashSet();
45: String namesA[] = null;
46:
47: /**
48: * Construct a new filter that accepts only the specified notification
49: * names.
50: *
51: * @param names Names of the notification types
52: */
53: public FixedNotificationFilter(String names[]) {
54: super ();
55: }
56:
57: /**
58: * Return the set of names that are accepted by this filter. If this
59: * filter accepts all attribute names, a zero length array will be
60: * returned.
61: */
62: public String[] getNames() {
63: synchronized (names) {
64: return ((String[]) names.toArray(new String[names.size()]));
65: }
66: }
67:
68: /**
69: * <p>Test whether notification enabled for this event.
70: * Return true if:</p>
71: * <ul>
72: * <li>Either the set of accepted names is empty (implying that all
73: * attribute names are of interest) or the set of accepted names
74: * includes the name of the attribute in this notification</li>
75: * </ul>
76: */
77: public boolean isNotificationEnabled(Notification notification) {
78:
79: if (notification == null)
80: return (false);
81: synchronized (names) {
82: if (names.size() < 1)
83: return (true);
84: else
85: return (names.contains(notification.getType()));
86: }
87:
88: }
89:
90: }
|