Source Code Cross Referenced for ManagementContext.java in  » ESB » servicemix » org » apache » servicemix » web » 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 » ESB » servicemix » org.apache.servicemix.web.jmx 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.servicemix.web.jmx;
018:
019:        import org.apache.activemq.Service;
020:        import org.apache.commons.logging.Log;
021:        import org.apache.commons.logging.LogFactory;
022:
023:        import javax.jms.JMSException;
024:        import javax.management.JMException;
025:        import javax.management.MBeanServer;
026:        import javax.management.MBeanServerFactory;
027:        import javax.management.MalformedObjectNameException;
028:        import javax.management.ObjectName;
029:
030:        import java.util.List;
031:
032:        /**
033:         * A Flow provides different dispatch policies within the NMR
034:         *
035:         * @version $Revision: 356583 $
036:         */
037:        public class ManagementContext implements  Service {
038:            /**
039:             * Default servicemix domain
040:             */
041:            public static String DEFAULT_DOMAIN = "org.apache.activemq";
042:
043:            private final static Log log = LogFactory
044:                    .getLog(ManagementContext.class);
045:
046:            private MBeanServer beanServer;
047:            private String jmxDomainName = DEFAULT_DOMAIN;
048:            private boolean useMBeanServer = true;
049:            private boolean createMBeanServer = true;
050:            private boolean locallyCreateMBeanServer = false;
051:
052:            public ManagementContext() {
053:                this (null);
054:            }
055:
056:            public ManagementContext(MBeanServer server) {
057:                this .beanServer = server;
058:            }
059:
060:            public void start() throws JMSException {
061:                // lets force the MBeanServer to be created if needed
062:                getMBeanServer();
063:            }
064:
065:            public void stop() throws JMSException {
066:                if (locallyCreateMBeanServer && beanServer != null) {
067:                    // check to see if the factory knows about this server
068:                    List list = MBeanServerFactory.findMBeanServer(null);
069:                    if (list != null && !list.isEmpty()
070:                            && list.contains(beanServer)) {
071:                        MBeanServerFactory.releaseMBeanServer(beanServer);
072:                    }
073:                }
074:            }
075:
076:            /**
077:             * @return Returns the jmxDomainName.
078:             */
079:            public String getJmxDomainName() {
080:                return jmxDomainName;
081:            }
082:
083:            /**
084:             * @param jmxDomainName
085:             *            The jmxDomainName to set.
086:             */
087:            public void setJmxDomainName(String jmxDomainName) {
088:                this .jmxDomainName = jmxDomainName;
089:            }
090:
091:            /**
092:             * Get the MBeanServer
093:             *
094:             * @return the MBeanServer
095:             */
096:            public MBeanServer getMBeanServer() {
097:                if (this .beanServer == null) {
098:                    this .beanServer = findMBeanServer();
099:                }
100:                return beanServer;
101:            }
102:
103:            /**
104:             * @return Returns the useMBeanServer.
105:             */
106:            public boolean isUseMBeanServer() {
107:                return useMBeanServer;
108:            }
109:
110:            /**
111:             * @param useMBeanServer
112:             *            The useMBeanServer to set.
113:             */
114:            public void setUseMBeanServer(boolean useMBeanServer) {
115:                this .useMBeanServer = useMBeanServer;
116:            }
117:
118:            /**
119:             * @return Returns the createMBeanServer flag.
120:             */
121:            public boolean isCreateMBeanServer() {
122:                return createMBeanServer;
123:            }
124:
125:            /**
126:             * @param enableJMX
127:             *            Set createMBeanServer.
128:             */
129:            public void setCreateMBeanServer(boolean enableJMX) {
130:                this .createMBeanServer = enableJMX;
131:            }
132:
133:            /**
134:             * Formulate and return the MBean ObjectName of a custom control MBean
135:             *
136:             * @param type
137:             * @param name
138:             * @return the JMX ObjectName of the MBean, or <code>null</code> if
139:             *         <code>customName</code> is invalid.
140:             */
141:            public ObjectName createCustomComponentMBeanName(String type,
142:                    String name) {
143:                ObjectName result = null;
144:                String tmp = jmxDomainName + ":" + "type="
145:                        + sanitizeString(type) + ",name="
146:                        + sanitizeString(name);
147:                try {
148:                    result = new ObjectName(tmp);
149:                } catch (MalformedObjectNameException e) {
150:                    log.error("Couldn't create ObjectName from: " + type
151:                            + " , " + name);
152:                }
153:                return result;
154:            }
155:
156:            /**
157:             * The ':' and '/' characters are reserved in ObjectNames
158:             *
159:             * @param in
160:             * @return sanitized String
161:             */
162:            private static String sanitizeString(String in) {
163:                String result = null;
164:                if (in != null) {
165:                    result = in.replace(':', '_');
166:                    result = result.replace('/', '_');
167:                    result = result.replace('\\', '_');
168:                }
169:                return result;
170:            }
171:
172:            /**
173:             * Retrive an System ObjectName
174:             *
175:             * @param domainName
176:             * @param containerName
177:             * @param theClass
178:             * @return the ObjectName
179:             * @throws MalformedObjectNameException
180:             */
181:            public static ObjectName getSystemObjectName(String domainName,
182:                    String containerName, Class theClass)
183:                    throws MalformedObjectNameException, NullPointerException {
184:                String tmp = domainName + ":" + "type=" + theClass.getName()
185:                        + ",name=" + getRelativeName(containerName, theClass);
186:                return new ObjectName(tmp);
187:            }
188:
189:            private static String getRelativeName(String containerName,
190:                    Class theClass) {
191:                String name = theClass.getName();
192:                int index = name.lastIndexOf(".");
193:                if (index >= 0 && (index + 1) < name.length()) {
194:                    name = name.substring(index + 1);
195:                }
196:                return containerName + "." + name;
197:            }
198:
199:            /**
200:             * Unregister an MBean
201:             *
202:             * @param name
203:             * @throws JMException
204:             */
205:            public void unregisterMBean(ObjectName name) throws JMException {
206:                if (beanServer != null && beanServer.isRegistered(name)) {
207:                    beanServer.unregisterMBean(name);
208:                }
209:            }
210:
211:            protected synchronized MBeanServer findMBeanServer() {
212:                MBeanServer result = null;
213:                // create the mbean server
214:                try {
215:                    if (useMBeanServer) {
216:                        // lets piggy back on another MBeanServer -
217:                        // we could be in an appserver!
218:                        List list = MBeanServerFactory.findMBeanServer(null);
219:                        if (list != null && list.size() > 0) {
220:                            result = (MBeanServer) list.get(0);
221:                        }
222:                    }
223:
224:                    if (result == null && createMBeanServer) {
225:                        result = MBeanServerFactory
226:                                .createMBeanServer(jmxDomainName);
227:                        locallyCreateMBeanServer = true;
228:                    }
229:                } catch (NoClassDefFoundError e) {
230:                    log.error("Couldnot load MBeanServer", e);
231:                } catch (Throwable e) {
232:                    // probably don't have access to system properties
233:                    log.error("Failed to initialize MBeanServer", e);
234:                }
235:                return result;
236:            }
237:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.