Source Code Cross Referenced for JmxConfigurator.java in  » Net » JGroups-2.4.1-sp3 » org » jgroups » 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 » Net » JGroups 2.4.1 sp3 » org.jgroups.jmx 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.jgroups.jmx;
002:
003:        import org.apache.commons.logging.Log;
004:        import org.apache.commons.logging.LogFactory;
005:        import org.jgroups.stack.ProtocolStack;
006:        import org.jgroups.util.Util;
007:
008:        import javax.management.*;
009:        import java.util.Vector;
010:        import java.util.Set;
011:        import java.util.Iterator;
012:
013:        /**
014:         * @author Bela Ban
015:         * @version $Id: JmxConfigurator.java,v 1.10 2006/08/09 13:02:21 belaban Exp $
016:         */
017:        public class JmxConfigurator {
018:            static final Log log = LogFactory.getLog(JmxConfigurator.class);
019:
020:            /**
021:             * Registers an already created channel with the MBeanServer. Creates an org.jgroups.jmx.JChannel which
022:             * delegates to the org.jgroups.JChannel and registers it. Optionally, this method will also try to
023:             * create one MBean proxy for each protocol in the channel's protocol stack, and register it as well.
024:             * @param channel
025:             * @param server
026:             * @param domain Has to be a JMX ObjectName of the domain, e.g. DefaultDomain:name=JGroups
027:             * @param register_protocols
028:             * @return org.jgroups.jmx.JChannel for the specified org.jgroups.JChannel
029:             */
030:            public static org.jgroups.jmx.JChannel registerChannel(
031:                    org.jgroups.JChannel channel, MBeanServer server,
032:                    String domain, String cluster_name,
033:                    boolean register_protocols) throws Exception {
034:                if (cluster_name == null)
035:                    cluster_name = channel != null ? channel.getClusterName()
036:                            : null;
037:                if (cluster_name == null)
038:                    cluster_name = "null";
039:                if (register_protocols) {
040:                    String tmp = domain + ":type=protocol,cluster="
041:                            + cluster_name;
042:                    registerProtocols(server, channel, tmp);
043:                }
044:                return registerChannel(channel, server, domain
045:                        + ":type=channel,cluster=" + cluster_name);
046:            }
047:
048:            /**
049:             * Registers an already created channel with the MBeanServer. Creates an org.jgroups.jmx.JChannel which
050:             * delegates to the org.jgroups.JChannel and registers it.
051:             * @param channel
052:             * @param server
053:             * @param name The JMX ObjectName 
054:             * @return org.jgroups.jmx.JChannel for the specified org.jgroups.JChannel
055:             */
056:            public static org.jgroups.jmx.JChannel registerChannel(
057:                    org.jgroups.JChannel channel, MBeanServer server,
058:                    String name) throws Exception {
059:                JChannel retval = new JChannel(channel);
060:                server.registerMBean(retval, new ObjectName(name));
061:                return retval;
062:            }
063:
064:            public static void unregisterChannel(MBeanServer server,
065:                    ObjectName name) throws Exception {
066:                if (server != null)
067:                    server.unregisterMBean(name);
068:            }
069:
070:            public static void unregisterChannel(MBeanServer server, String name)
071:                    throws Exception {
072:                if (server != null)
073:                    server.unregisterMBean(new ObjectName(name));
074:            }
075:
076:            public static org.jgroups.jmx.JChannelFactory registerChannelFactory(
077:                    org.jgroups.JChannelFactory factory, MBeanServer server,
078:                    String name) throws Exception {
079:                JChannelFactory retval = new JChannelFactory(factory);
080:                server.registerMBean(retval, new ObjectName(name));
081:                return retval;
082:            }
083:
084:            /**
085:             * Takes all protocols of an existing stack, creates corresponding MBean proxies and registers them with
086:             * the MBean server
087:             * @param channel
088:             * @param prefix
089:             */
090:            public static void registerProtocols(MBeanServer server,
091:                    org.jgroups.JChannel channel, String prefix)
092:                    throws Exception {
093:                ProtocolStack stack = channel.getProtocolStack();
094:                Vector protocols = stack.getProtocols();
095:                org.jgroups.stack.Protocol prot;
096:                org.jgroups.jmx.Protocol p = null;
097:                for (int i = 0; i < protocols.size(); i++) {
098:                    prot = (org.jgroups.stack.Protocol) protocols.get(i);
099:                    try {
100:                        p = findProtocol(prot);
101:                    } catch (ClassNotFoundException e) {
102:                        p = null;
103:                    } catch (Throwable e) {
104:                        log.error("failed creating a JMX wrapper instance for "
105:                                + prot, e);
106:                        p = null;
107:                    }
108:                    if (p == null)
109:                        p = new org.jgroups.jmx.Protocol(prot);
110:                    ObjectName prot_name = new ObjectName(prefix + ",protocol="
111:                            + prot.getName());
112:                    server.registerMBean(p, prot_name);
113:                }
114:            }
115:
116:            public static void unregisterProtocols(MBeanServer server,
117:                    org.jgroups.JChannel channel, String channel_name) {
118:                ProtocolStack stack = channel.getProtocolStack();
119:                Vector protocols = stack.getProtocols();
120:                org.jgroups.stack.Protocol prot;
121:                ObjectName prot_name = null;
122:                for (int i = 0; i < protocols.size(); i++) {
123:                    prot = (org.jgroups.stack.Protocol) protocols.get(i);
124:                    try {
125:                        prot_name = new ObjectName(channel_name + ",protocol="
126:                                + prot.getName());
127:                        server.unregisterMBean(prot_name);
128:                    } catch (Throwable e) {
129:                        log.error("failed to unregister " + prot_name, e);
130:                    }
131:                }
132:            }
133:
134:            /**
135:             * Unregisters object_name and everything under it
136:             * @param object_name
137:             */
138:            public static void unregister(MBeanServer server, String object_name)
139:                    throws Exception {
140:                Set mbeans = server.queryNames(new ObjectName(object_name),
141:                        null);
142:                if (mbeans != null) {
143:                    ObjectName name;
144:                    for (Iterator it = mbeans.iterator(); it.hasNext();) {
145:                        name = (ObjectName) it.next();
146:                        server.unregisterMBean(name);
147:                    }
148:                }
149:            }
150:
151:            protected static Protocol findProtocol(
152:                    org.jgroups.stack.Protocol prot)
153:                    throws ClassNotFoundException, IllegalAccessException,
154:                    InstantiationException {
155:                Protocol p;
156:                String prot_name = prot.getClass().getName();
157:                String clname = prot_name.replaceFirst("org.jgroups.",
158:                        "org.jgroups.jmx.");
159:                Class cl = Util.loadClass(clname, JmxConfigurator.class);
160:                if (cl != null) {
161:                    p = (Protocol) cl.newInstance();
162:                    p.attachProtocol(prot);
163:                    return p;
164:                }
165:                return null;
166:            }
167:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.