Source Code Cross Referenced for JMXVisitor.java in  » Inversion-of-Control » PicoContainer » org » picocontainer » gems » jmx » 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 » Inversion of Control » PicoContainer » org.picocontainer.gems.jmx 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*****************************************************************************
002:         * Copyright (C) NanoContainer Organization. All rights reserved.            *
003:         * ------------------------------------------------------------------------- *
004:         * The software in this package is published under the terms of the BSD      *
005:         * style license a copy of which has been included with this distribution in *
006:         * the LICENSE.txt file.                                                     *
007:         *                                                                           *
008:         * Original code by Michael Ward                                    		 *
009:         *****************************************************************************/package org.picocontainer.gems.jmx;
010:
011:        import java.util.HashSet;
012:        import java.util.Set;
013:
014:        import javax.management.DynamicMBean;
015:        import javax.management.JMException;
016:        import javax.management.MBeanServer;
017:        import javax.management.ObjectInstance;
018:        import javax.management.ObjectName;
019:
020:        import org.picocontainer.ComponentAdapter;
021:        import org.picocontainer.PicoContainer;
022:        import org.picocontainer.visitors.TraversalCheckingVisitor;
023:
024:        /**
025:         * A {@link org.picocontainer.PicoVisitor} to register JMX components for components of a {@link PicoContainer} tree in
026:         * a {@link MBeanServer}.
027:         * @author Michael Ward
028:         * @author Jörg Schaible
029:         * @version $Revision: 3905 $
030:         */
031:        public class JMXVisitor extends TraversalCheckingVisitor {
032:            private final DynamicMBeanProvider[] mBeanProviders;
033:            private final MBeanServer mBeanServer;
034:            private final Set visited;
035:            private final Set registeredInfo;
036:            private PicoContainer picoContainer;
037:
038:            /**
039:             * Construct a JMXVisitor. This instance will register by default any component in the {@link MBeanServer}, that is
040:             * already a {@link DynamicMBean}. The {@link ObjectName} will use the default domain of the MBeanServer and has a
041:             * <em>type</em> key with the class name (without package name) as value.
042:             * @param server The {@link MBeanServer}to use for registering the MBeans.
043:             */
044:            public JMXVisitor(final MBeanServer server) {
045:                this (
046:                        server,
047:                        new DynamicMBeanProvider[] { new DynamicMBeanComponentProvider() });
048:            }
049:
050:            /**
051:             * Construct a JMXVisitor.
052:             * @param server The {@link MBeanServer} to use for registering the MBeans.
053:             * @param providers The providers to deliver the DynamicMBeans.
054:             */
055:            public JMXVisitor(final MBeanServer server,
056:                    final DynamicMBeanProvider[] providers) {
057:                if (server == null) {
058:                    throw new NullPointerException(
059:                            "MBeanServer may not be null");
060:                }
061:                if (providers == null) {
062:                    throw new NullPointerException(
063:                            "DynamicMBeanProvider[] may not be null");
064:                }
065:                if (providers.length == 0) {
066:                    throw new IllegalArgumentException(
067:                            "DynamicMBeanProvider[] may not be empty");
068:                }
069:                mBeanServer = server;
070:                mBeanProviders = providers;
071:                visited = new HashSet();
072:                registeredInfo = new HashSet();
073:            }
074:
075:            /**
076:             * Entry point for the visitor traversal.
077:             * @return Returns a {@link Set} with all ObjectInstance instances retrieved from the {@link MBeanServer} for the
078:             *         registered MBeans.
079:             * @see org.picocontainer.visitors.AbstractPicoVisitor#traverse(java.lang.Object)
080:             */
081:            public Object traverse(final Object node) {
082:                super .traverse(node);
083:                picoContainer = null;
084:                final Set set = new HashSet(registeredInfo);
085:                registeredInfo.clear();
086:                return set;
087:            }
088:
089:            /**
090:             * Provides the PicoContainer, that can resolve the components to register as MBean.
091:             * @see org.picocontainer.PicoVisitor#visitContainer(org.picocontainer.PicoContainer)
092:             */
093:            public void visitContainer(final PicoContainer pico) {
094:                super .visitContainer(pico);
095:                picoContainer = pico;
096:                visited.clear();
097:            }
098:
099:            /**
100:             * Register the component as MBean. The implementation uses the known DynamicMBeanProvider instances to get the
101:             * MBean from the component.
102:             * @see org.picocontainer.PicoVisitor#visitComponentAdapter(org.picocontainer.ComponentAdapter)
103:             */
104:            public void visitComponentAdapter(
105:                    final ComponentAdapter componentAdapter) {
106:                super .visitComponentAdapter(componentAdapter);
107:                if (picoContainer == null) {
108:                    throw new JMXRegistrationException(
109:                            "Cannot start JMXVisitor traversal with a ComponentAdapter");
110:                }
111:                if (!visited.contains(componentAdapter.getComponentKey())) {
112:                    visited.add(componentAdapter.getComponentKey());
113:                    for (final DynamicMBeanProvider provider : mBeanProviders) {
114:                        final JMXRegistrationInfo info = provider.provide(
115:                                picoContainer, componentAdapter);
116:                        if (info != null) {
117:                            registeredInfo.add(register(info.getMBean(), info
118:                                    .getObjectName()));
119:                            break;
120:                        }
121:                    }
122:                }
123:            }
124:
125:            /**
126:             * Register a MBean in the MBeanServer.
127:             * @param dynamicMBean the {@link DynamicMBean} to register.
128:             * @param objectName the {@link ObjectName} of the MBean registered the {@link MBeanServer}.
129:             * @return Returns the {@link ObjectInstance} returned from the MBeanServer after registration.
130:             * @throws JMXRegistrationException Thrown if MBean cannot be registered.
131:             */
132:            protected ObjectInstance register(final DynamicMBean dynamicMBean,
133:                    final ObjectName objectName)
134:                    throws JMXRegistrationException {
135:                try {
136:                    return mBeanServer.registerMBean(dynamicMBean, objectName);
137:                } catch (final JMException e) {
138:                    throw new JMXRegistrationException(
139:                            "Unable to register MBean to MBean Server", e);
140:                }
141:            }
142:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.