Source Code Cross Referenced for ModelMBeanNotificationPublisher.java in  » J2EE » spring-framework-2.5 » org » springframework » jmx » export » 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 » J2EE » spring framework 2.5 » org.springframework.jmx.export.notification 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2007 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.jmx.export.notification;
018:
019:        import javax.management.AttributeChangeNotification;
020:        import javax.management.MBeanException;
021:        import javax.management.Notification;
022:        import javax.management.ObjectName;
023:        import javax.management.modelmbean.ModelMBean;
024:        import javax.management.modelmbean.ModelMBeanNotificationBroadcaster;
025:
026:        import org.springframework.util.Assert;
027:
028:        /**
029:         * {@link NotificationPublisher} implementation that uses the infrastructure
030:         * provided by the {@link ModelMBean} interface to track
031:         * {@link javax.management.NotificationListener javax.management.NotificationListeners}
032:         * and send {@link Notification Notifications} to those listeners.
033:         *
034:         * @author Rob Harrop
035:         * @author Juergen Hoeller
036:         * @author Rick Evans
037:         * @since 2.0
038:         * @see javax.management.modelmbean.ModelMBeanNotificationBroadcaster
039:         * @see NotificationPublisherAware
040:         */
041:        public class ModelMBeanNotificationPublisher implements 
042:                NotificationPublisher {
043:
044:            /**
045:             * The {@link ModelMBean} instance wrapping the managed resource into which this
046:             * <code>NotificationPublisher</code> will be injected.
047:             */
048:            private final ModelMBeanNotificationBroadcaster modelMBean;
049:
050:            /**
051:             * The {@link ObjectName} associated with the {@link ModelMBean modelMBean}.
052:             */
053:            private final ObjectName objectName;
054:
055:            /**
056:             * The managed resource associated with the {@link ModelMBean modelMBean}.
057:             */
058:            private final Object managedResource;
059:
060:            /**
061:             * Create a new instance of the {@link ModelMBeanNotificationPublisher} class
062:             * that will publish all {@link javax.management.Notification Notifications}
063:             * to the supplied {@link ModelMBean}.
064:             * @param modelMBean the target {@link ModelMBean}; must not be <code>null</code>
065:             * @param objectName the {@link ObjectName} of the source {@link ModelMBean}
066:             * @param managedResource the managed resource exposed by the supplied {@link ModelMBean}
067:             * @throws IllegalArgumentException if any of the parameters is <code>null</code> 
068:             */
069:            public ModelMBeanNotificationPublisher(
070:                    ModelMBeanNotificationBroadcaster modelMBean,
071:                    ObjectName objectName, Object managedResource) {
072:
073:                Assert.notNull(modelMBean, "'modelMBean' must not be null");
074:                Assert.notNull(objectName, "'objectName' must not be null");
075:                Assert.notNull(managedResource,
076:                        "'managedResource' must not be null");
077:                this .modelMBean = modelMBean;
078:                this .objectName = objectName;
079:                this .managedResource = managedResource;
080:            }
081:
082:            /**
083:             * Send the supplied {@link Notification} using the wrapped
084:             * {@link ModelMBean} instance.
085:             * @param notification the {@link Notification} to be sent
086:             * @throws IllegalArgumentException if the supplied <code>notification</code> is <code>null</code>
087:             * @throws UnableToSendNotificationException if the supplied <code>notification</code> could not be sent
088:             */
089:            public void sendNotification(Notification notification) {
090:                Assert.notNull(notification, "Notification must not be null");
091:                replaceNotificationSourceIfNecessary(notification);
092:                try {
093:                    if (notification instanceof  AttributeChangeNotification) {
094:                        this .modelMBean
095:                                .sendAttributeChangeNotification((AttributeChangeNotification) notification);
096:                    } else {
097:                        this .modelMBean.sendNotification(notification);
098:                    }
099:                } catch (MBeanException ex) {
100:                    throw new UnableToSendNotificationException(
101:                            "Unable to send notification [" + notification
102:                                    + "]", ex);
103:                }
104:            }
105:
106:            /**
107:             * From the {@link Notification javadoc}:
108:             * <p><i>"It is strongly recommended that notification senders use the object name
109:             * rather than a reference to the MBean object as the source."</i>
110:             * @param notification the {@link Notification} whose
111:             * {@link javax.management.Notification#getSource()} might need massaging
112:             */
113:            private void replaceNotificationSourceIfNecessary(
114:                    Notification notification) {
115:                if (notification.getSource() == null
116:                        || notification.getSource()
117:                                .equals(this.managedResource)) {
118:                    notification.setSource(this.objectName);
119:                }
120:            }
121:
122:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.