Source Code Cross Referenced for MBeanServerNotificationFilter.java in  » JMX » jfoxmx » javax » management » relation » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » JMX » jfoxmx » javax.management.relation 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* JFox, the OpenSource J2EE Application Server
002:         *
003:         * Copyright (C) 2002 huihoo.org
004:         * Distributable under GNU LGPL license
005:         * See the GNU Lesser General Public License for more details.
006:         */
007:
008:        package javax.management.relation;
009:
010:        import java.util.Vector;
011:        import java.util.Set;
012:        import java.util.HashSet;
013:        import javax.management.NotificationFilterSupport;
014:        import javax.management.MBeanServerNotification;
015:        import javax.management.ObjectName;
016:        import javax.management.Notification;
017:
018:        /**
019:         * This filter allows to filter MBeanServerNotification notifications by
020:         * selecting the ObjectNames of interest and the operations (registration,
021:         * unregistration, both) of interest (corresponding to notification
022:         * types).
023:         *
024:         * @author <a href="mailto:young_yy@hotmail.org">Young Yang</a>
025:         */
026:
027:        public class MBeanServerNotificationFilter extends
028:                NotificationFilterSupport {
029:
030:            private Set selectedNames = new HashSet(); // null for select all
031:            private Set deselectedNames = new HashSet(); // null for deselect all
032:
033:            private boolean enableAll = false;
034:            private boolean disableAll = false;
035:
036:            /**
037:             * Creates a filter selecting all MBeanServerNotification notifications for
038:             * all ObjectNames
039:             */
040:            public MBeanServerNotificationFilter() {
041:
042:                super ();
043:                enableType(MBeanServerNotification.REGISTRATION_NOTIFICATION);
044:                enableType(MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
045:
046:            }
047:
048:            /**
049:             * Disables any MBeanServerNotification (i.e. all ObjectNames
050:             * deselected)
051:             */
052:            public synchronized void disableAllObjectNames() {
053:                selectedNames.clear();
054:                deselectedNames.clear();
055:                enableAll = false;
056:                disableAll = true;
057:            }
058:
059:            /**
060:             * Disables MBeanServerNotifications concerning given ObjectName.
061:             *
062:             * @param objectName  ObjectName no longer of interest
063:             *
064:             * @exception IllegalArgumentException  if the given ObjectName is null
065:             */
066:            public synchronized void disableObjectName(ObjectName objectName)
067:                    throws IllegalArgumentException {
068:
069:                if (objectName == null)
070:                    throw new IllegalArgumentException(
071:                            "Invalid parameter:Null ObjectName");
072:
073:                if (selectedNames.contains(objectName))
074:                    selectedNames.remove(objectName);
075:
076:                if (!(deselectedNames.contains(objectName)))
077:                    deselectedNames.add(objectName);
078:            }
079:
080:            synchronized void disableObjectNames(ObjectName[] objectNames)
081:                    throws IllegalArgumentException {
082:                for (int i = 0; i < objectNames.length; i++) {
083:                    this .disableObjectName(objectNames[i]);
084:                }
085:            }
086:
087:            /**
088:             * Enables all MBeanServerNotifications (i.e. all ObjectNames selected)
089:             */
090:            public synchronized void enableAllObjectNames() {
091:                selectedNames.clear();
092:                deselectedNames.clear();
093:                enableAll = true;
094:                disableAll = false;
095:            }
096:
097:            /**
098:             * Enables MBeanServerNotifications concerning given ObjectName.
099:             *
100:             * @param objectName  ObjectName of interest
101:             *
102:             * @exception IllegalArgumentException  if the given ObjectName is null
103:             */
104:            public synchronized void enableObjectName(ObjectName objectName)
105:                    throws IllegalArgumentException {
106:
107:                if (objectName == null)
108:                    throw new IllegalArgumentException(
109:                            "Invalid parameter:Null ObjectName");
110:
111:                if (deselectedNames.contains(objectName))
112:                    deselectedNames.remove(objectName);
113:
114:                if (!(selectedNames.contains(objectName)))
115:                    selectedNames.add(objectName);
116:            }
117:
118:            synchronized void enableObjectNames(ObjectName[] objectNames)
119:                    throws IllegalArgumentException {
120:                for (int i = 0; i < objectNames.length; i++) {
121:                    this .enableObjectName(objectNames[i]);
122:                }
123:            }
124:
125:            /**
126:             * Gets all the ObjectNames enabled.
127:             *
128:             * @return Vector of ObjectNames:
129:             * <P>- null means all ObjectNames are implicitly selected, except the
130:             * ObjectNames explicitly deselected
131:             * <P>- empty means all ObjectNames are deselected, i.e. no ObjectName
132:             * selected.
133:             */
134:            public synchronized Vector getEnabledObjectNames() {
135:                if (enableAll)
136:                    return null;
137:                return new Vector(selectedNames);
138:            }
139:
140:            /**
141:             * Gets all the ObjectNames disabled.
142:             *
143:             * @return Vector of ObjectNames:
144:             * <P>- null means all ObjectNames are implicitly deselected, except the
145:             * ObjectNames explicitly selected
146:             * <P>- empty means all ObjectNames are selected, i.e. no ObjectName
147:             * deselected.
148:             */
149:            public synchronized Vector getDisabledObjectNames() {
150:                if (disableAll)
151:                    return null;
152:                return new Vector(deselectedNames);
153:            }
154:
155:            //
156:            // NotificationFilter interface
157:            //
158:
159:            /**
160:             * Invoked before sending the specified notification to the listener.
161:             * <P>If:
162:             * <P>- the ObjectName of the concerned MBean is selected (explicitly OR
163:             * (implicitly and not explicitly deselected))
164:             * <P>AND
165:             * <P>- the type of the operation (registration or unregistration) is
166:             * selected
167:             * <P>then the notification is sent to the listener.
168:             *
169:             * @param notif  The notification to be sent.
170:             *
171:             * @return true if the notification has to be sent to the listener, false
172:             * otherwise.
173:             *
174:             * @exception IllegalArgumentException  if null parameter
175:             */
176:            public synchronized boolean isNotificationEnabled(Notification notif)
177:                    throws IllegalArgumentException {
178:
179:                if (notif == null)
180:                    throw new IllegalArgumentException(
181:                            "Invalid parameter: null notification");
182:
183:                if (!super .isNotificationEnabled(notif))
184:                    return false; // type check
185:
186:                // Check the ObjectName
187:                MBeanServerNotification mbsNtf = (MBeanServerNotification) notif;
188:                ObjectName objName = mbsNtf.getMBeanName();
189:
190:                if (selectedNames.contains(objName)) { // select explicit, return true
191:                    return true;
192:                } else if (enableAll && !deselectedNames.contains(objName)) { // not select explicit,but enable all && not deselect explicit
193:                    // if enable all ,must be not disable all
194:                    return true;
195:                }
196:
197:                return false; // else return false;
198:
199:            }
200:
201:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.