Source Code Cross Referenced for NotificationServiceImpl.java in  » ESB » open-esb » com » sun » esb » management » impl » notification » 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 » ESB » open esb » com.sun.esb.management.impl.notification 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)NotificationServiceImpl.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.esb.management.impl.notification;
030:
031:        import java.io.IOException;
032:        import java.util.ArrayList;
033:        import java.util.concurrent.ExecutorService;
034:        import java.util.concurrent.Executors;
035:
036:        import javax.management.InstanceNotFoundException;
037:        import javax.management.MBeanServerConnection;
038:        import javax.management.Notification;
039:        import javax.management.NotificationListener;
040:        import javax.management.ObjectName;
041:
042:        import com.sun.esb.management.api.notification.EventNotification;
043:        import com.sun.esb.management.api.notification.EventNotificationListener;
044:        import com.sun.esb.management.api.notification.NotificationService;
045:        import com.sun.esb.management.base.services.BaseServiceImpl;
046:        import com.sun.esb.management.common.ManagementRemoteException;
047:
048:        /**
049:         * @author graj
050:         *
051:         */
052:        public class NotificationServiceImpl extends BaseServiceImpl implements 
053:                NotificationListener, NotificationService {
054:
055:            static final long serialVersionUID = -1L;
056:
057:            /**
058:             * Store a list of listeners
059:             */
060:            private ArrayList<EventNotificationListener> listeners = new ArrayList<EventNotificationListener>();
061:
062:            /**
063:             * Executor service to send notifications on threads from a pool.
064:             */
065:            private ExecutorService executorService;
066:
067:            /** Constructor - Constructs a new instance of NotificationServiceImpl */
068:            public NotificationServiceImpl() {
069:                super (null, false);
070:            }
071:
072:            /**
073:             * Constructor - Constructs a new instance of NotificationServiceImpl
074:             * 
075:             * @param serverConnection
076:             */
077:            public NotificationServiceImpl(
078:                    MBeanServerConnection serverConnection) {
079:                super (serverConnection, false);
080:            }
081:
082:            /**
083:             * Constructor - Constructs a new instance of NotificationServiceImpl
084:             * 
085:             * @param serverConnection
086:             * @param isRemoteConnection
087:             */
088:            public NotificationServiceImpl(
089:                    MBeanServerConnection serverConnection,
090:                    boolean isRemoteConnection) {
091:                super (serverConnection, isRemoteConnection);
092:                // Create the thread pool to be used for sending notifications
093:                executorService = Executors.newCachedThreadPool();
094:                registerForNotifications();
095:            }
096:
097:            /**
098:             * Register for notifications
099:             */
100:            protected void registerForNotifications() {
101:                try {
102:                    ObjectName mbeanName = getNotificationServiceMBeanObjectName();
103:                    this .remoteConnection.addNotificationListener(mbeanName,
104:                            this , null, new Object());
105:                } catch (InstanceNotFoundException e) {
106:                } catch (ManagementRemoteException e) {
107:                } catch (IOException e) {
108:                }
109:            }
110:
111:            /**
112:             * Handle the Event Notification
113:             * @param the notification
114:             * @param the handback object
115:             *  
116:             * @see javax.management.NotificationListener#handleNotification(javax.management.Notification, java.lang.Object)
117:             */
118:            public void handleNotification(Notification notification,
119:                    Object handback) {
120:                EventNotificationImpl event = new EventNotificationImpl(
121:                        notification.getSource());
122:                event.setNotification(notification);
123:                executorService.execute(new NotificationSender(this .listeners,
124:                        event));
125:            }
126:
127:            /**
128:             * Add notification listener
129:             * @param an EventNotificationListener object
130:             * @see com.sun.esb.management.api.notification.NotificationService#addNotificationEventListener(com.sun.esb.management.api.notification.EventNotificationListener)
131:             */
132:            public void addNotificationEventListener(
133:                    EventNotificationListener aListener)
134:                    throws ManagementRemoteException {
135:                listeners.add(aListener);
136:            }
137:
138:            /**
139:             * Remove notification listener
140:             * @param an EventNotificationListener object
141:             * @see com.sun.esb.management.api.notification.NotificationService#removeNotificationEventListener(com.sun.esb.management.api.notification.EventNotificationListener)
142:             */
143:            public void removeNotificationEventListener(
144:                    EventNotificationListener aListener) {
145:                listeners.remove(aListener);
146:            }
147:
148:            /**
149:             * Class to send out notifications on a separate thread 
150:             * @author graj
151:             */
152:            class NotificationSender implements  Runnable {
153:                private ArrayList<EventNotificationListener> listeners = new ArrayList<EventNotificationListener>();
154:
155:                /**
156:                 * Notification instance to be sent.
157:                 */
158:                EventNotification eventNotification;
159:
160:                /**
161:                 * Constructor.
162:                 *
163:                 * @param en the instance of EventNotifier that called this constructor.
164:                 * @param notif the JMX Notification to be sent.
165:                 */
166:                NotificationSender(ArrayList<EventNotificationListener> en,
167:                        EventNotification notif) {
168:                    listeners = en;
169:                    eventNotification = notif;
170:                }
171:
172:                /**
173:                 * Run the actual sending of the notification. This runs on a thread
174:                 * from the pool created by Executors.newCachedThreadPool().
175:                 */
176:                public void run() {
177:                    ArrayList<EventNotificationListener> list = null;
178:                    synchronized (this ) {
179:                        list = (ArrayList<EventNotificationListener>) listeners
180:                                .clone();
181:                    }
182:                    for (EventNotificationListener aListener : list) {
183:                        aListener.processNotification(eventNotification);
184:                    }
185:                }
186:            }
187:
188:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.