Source Code Cross Referenced for NotificationBroadcasterSupport.java in  » JMX » XMOJO » javax » management » 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 » XMOJO » javax.management 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * The XMOJO Project 5
003:         * Copyright © 2003 XMOJO.org. All rights reserved.
004:
005:         * NO WARRANTY
006:
007:         * BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR
008:         * THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
009:         * OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
010:         * PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
011:         * OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
012:         * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
013:         * TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE
014:         * LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
015:         * REPAIR OR CORRECTION.
016:
017:         * IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
018:         * ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE
019:         * THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
020:         * GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
021:         * USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF
022:         * DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
023:         * PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE),
024:         * EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
025:         * SUCH DAMAGES.
026:         **/package javax.management;
027:
028:        import java.lang.reflect.Array;
029:        import java.util.ArrayList;
030:        import java.util.Enumeration;
031:        import java.util.Hashtable;
032:        import java.util.Vector;
033:
034:        import com.adventnet.agent.utilities.scheduler.*;
035:
036:        import com.adventnet.jmx.NotificationHandler;
037:        import com.adventnet.jmx.NotificationThread;
038:        import com.adventnet.agent.logging.Log;
039:        import com.adventnet.agent.logging.LogFactory;
040:
041:        /**
042:         * This class provides an implementation of NotificationBroadcaster. It could
043:         * be used as a super class of MBean to deal with notification. If inheritance
044:         * can't be used, the following code can be used as an example for
045:         * NotificationBroadcaster implementation.
046:         */
047:        public class NotificationBroadcasterSupport implements 
048:                NotificationBroadcaster {
049:            /**
050:             * Hastable containing the Listener and hand-back objects.
051:             */
052:            private Hashtable notifTable = null;
053:
054:            private Hashtable info = null;
055:
056:            private Log log = null;
057:
058:            private Vector notifList = null;
059:
060:            private static Scheduler scheduler = null;
061:
062:            private static int MAX_THREADS = 4;
063:
064:            /**
065:             * Creates a NotificationBraoadCasterSupport. Default constructor.
066:             */
067:            public NotificationBroadcasterSupport() {
068:                createLogger();
069:                notifTable = new Hashtable();
070:                info = new Hashtable();
071:                notifList = new Vector();
072:
073:                if (scheduler == null) {
074:                    scheduler = Scheduler.createScheduler(
075:                            "NOTIFICATIONBROADCASTERSUPPORT", MAX_THREADS);
076:                    scheduler.start();
077:                    log.trace("JMX BROADCASTER Scheduler instantiated");
078:                }
079:            }
080:
081:            /**
082:             * Enables a couple (listener,handback) for a registered MBean to be added.
083:             *
084:             * @param listener The listener object which will handles notifications
085:             * 				emitted by the registered MBean.
086:             *
087:             * @param filter The filter object. If not specified, no filtering will
088:             * 				be performed before handling notifications.
089:             *
090:             * @param handback The context to be sent to the listener when a
091:             * 				notification is emitted.
092:             *
093:             * @throws java.lang.IllegalArgumentException - Listener parameter is null.
094:             */
095:            public void addNotificationListener(NotificationListener listener,
096:                    NotificationFilter filter, Object handback) {
097:                if (listener == null)
098:                    throw new RuntimeOperationsException(
099:                            new IllegalArgumentException(
100:                                    "Listener cannot be null!!!"));
101:
102:                ArrayList[] obj = (ArrayList[]) notifTable.get(listener);
103:
104:                if (obj == null) {
105:                    obj = new ArrayList[2];
106:                    obj[0] = new ArrayList();
107:                    obj[1] = new ArrayList();
108:                    obj[0].add(filter);
109:                    obj[1].add(handback);
110:
111:                    notifTable.put(listener, obj);
112:                } else {
113:                    boolean flag = false;
114:                    Object[] handbacks = obj[1].toArray();
115:
116:                    for (int i = 0; i < handbacks.length; i++) {
117:                        if (handbacks[i].equals(handback)) {
118:                            flag = true;
119:                            break;
120:                        }
121:                    }
122:
123:                    if (!flag) {
124:                        obj[0].add(filter);
125:                        obj[1].add(handback);
126:                    }
127:                }
128:            }
129:
130:            /**
131:             * Enables a listener for an MBean to be removed.
132:             * All couple (listener, handback) are removed.
133:             *
134:             * @param listener The listener object which will handles notifications
135:             * 				emitted by the registered MBean.
136:             *
137:             * @throws ListenerNotFoundException The listener is not registered
138:             * 				in the MBean.
139:             */
140:            public void removeNotificationListener(NotificationListener listener)
141:                    throws ListenerNotFoundException {
142:                Object list = notifTable.get(listener);
143:
144:                if (list == null) {
145:                    throw new ListenerNotFoundException(
146:                            "Unknown Listener is being passed !!!");
147:                }
148:
149:                notifTable.remove(listener);
150:            }
151:
152:            /**
153:             * Returns a NotificationInfo object contaning the name of the
154:             * Java class of the notification and the notification types sent.
155:             *
156:             * @return This returns a array of MBeanNotificationInfo which
157:             * 				contains the notification information.
158:             */
159:            public MBeanNotificationInfo[] getNotificationInfo() {
160:                MBeanNotificationInfo[] toRet = new MBeanNotificationInfo[info
161:                        .size()];
162:                int i = 0;
163:                for (Enumeration e = info.keys(); e.hasMoreElements();) {
164:                    String key = (String) e.nextElement();
165:                    ArrayList list = (ArrayList) info.get(key);
166:                    String[] strArray = (String[]) list.toArray(new String[0]);
167:
168:                    toRet[i++] = new MBeanNotificationInfo(strArray, key,
169:                            "Notification description");
170:                }
171:                return toRet;
172:            }
173:
174:            /**
175:             * Enables a MBean to send a notification.
176:             *
177:             * @param notif - The notification to send.
178:             */
179:            public void sendNotification(Notification notif) {
180:                for (Enumeration e = notifTable.keys(); e.hasMoreElements();) {
181:                    NotificationListener nl = (NotificationListener) e
182:                            .nextElement();
183:
184:                    ArrayList[] list = (ArrayList[]) notifTable.get(nl);
185:
186:                    Object[] filters = list[0].toArray();
187:                    Object[] handbacks = list[1].toArray();
188:
189:                    try {
190:                        for (int i = 0; i < filters.length; i++) {
191:                            NotificationHandler hdlr = new NotificationHandler(
192:                                    (NotificationFilter) filters[i], nl,
193:                                    handbacks[i], notif, info);
194:
195:                            Vector myVect = new Vector();
196:
197:                            myVect.addElement(hdlr);
198:
199:                            Runnable runnable = new NotificationThread(myVect,
200:                                    this .info);
201:
202:                            scheduler.scheduleTask(runnable, null);
203:                            log.debug("Task Scheduled");
204:                            runnable = null;
205:                        }
206:                    } catch (Exception ex) {
207:                        log.error("Exception in SendNotification" + ex);
208:                    }
209:                }
210:            }
211:
212:            //------------------------- Private methods ---------------------------//
213:
214:            private void createLogger() {
215:                try {
216:                    log = LogFactory.getInstance("JMX");
217:                } catch (Exception e) {
218:                    e.printStackTrace();
219:                }
220:            }
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.