User: juhalindfors
Date: 01/12/08 16:23:01
Modified: src/main/javax/management MBeanServerFactory.java
Log:
different servers for different people..
use -Djbossmx.mbean.server.class=yourClass to override the default
mbean server implementation
Revision Changes Path
1.2 +114 -21 jmx/src/main/javax/management/MBeanServerFactory.java
Index: MBeanServerFactory.java
===================================================================
RCS file: /cvsroot/jboss/jmx/src/main/javax/management/MBeanServerFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MBeanServerFactory.java 2001/12/03 02:08:47 1.1
+++ MBeanServerFactory.java 2001/12/09 00:23:00 1.2
@@ -1,5 +1,8 @@
/*
- * LGPL
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
*/
package javax.management;
@@ -8,45 +11,135 @@
import java.util.HashMap;
import java.util.ArrayList;
-public class MBeanServerFactory extends java.lang.Object {
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+/**
+ * MBeanServerFactory is used to create instances of MBean servers.
+ *
+ * @see javax.management.MBeanServer
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>.
+ * @version $Revision: 1.2 $
+ *
+ */
+public class MBeanServerFactory
+{
+
+ // Constants -----------------------------------------------------
+ private final static String DEFAULT_DOMAIN = "DefaultDomain";
+
+ // Attributes ----------------------------------------------------
private static Map serverMap = new HashMap();
-
- public static void releaseMBeanServer(MBeanServer mbeanServer) {
- throw new Error("NYI");
+
+ // Public --------------------------------------------------------
+ public static void releaseMBeanServer(MBeanServer mbeanServer)
+ {
+ try
+ {
+ String agentID = (String)mbeanServer.getAttribute(
+ new
ObjectName("JMImplementation:type=MBeanServerDelegate"),
+ "MBeanServerId");
+
+ Object server = serverMap.remove(agentID);
+
+ if (server == null)
+ throw new IllegalArgumentException("MBean server reference not found.");
+ }
+ catch (MalformedObjectNameException e)
+ {
+ throw new Error(e.toString());
+ }
+ catch (JMException e)
+ {
+ throw new Error("Cannot retrieve AgentID: " + e.toString());
+ }
}
- public static MBeanServer createMBeanServer() {
- return createMBeanServer("DefaultDomain");
+ public static MBeanServer createMBeanServer()
+ {
+ return createMBeanServer(DEFAULT_DOMAIN);
}
- public static MBeanServer createMBeanServer(String domain) {
- MBeanServer server = new org.jboss.mx.server.MBeanServerImpl(domain);
- serverMap.put(createAgentID(), server);
- return server;
+ public static MBeanServer createMBeanServer(String domain)
+ {
+ return createMBeanServer(domain, true);
}
- public static MBeanServer newMBeanServer() {
- return new org.jboss.mx.server.MBeanServerImpl("DefaultDomain");
+ public static MBeanServer newMBeanServer()
+ {
+ return newMBeanServer(DEFAULT_DOMAIN);
}
-
- public static MBeanServer newMBeanServer(String domain) {
- return new org.jboss.mx.server.MBeanServerImpl(domain);
+
+ public static MBeanServer newMBeanServer(String domain)
+ {
+ return createMBeanServer(domain, false);
}
- public static java.util.ArrayList findMBeanServer(String AgentId) {
- if (AgentId != null) {
+ public static ArrayList findMBeanServer(String agentId)
+ {
+ if (agentId != null)
+ {
ArrayList list = new ArrayList(1);
- list.add(serverMap.get(AgentId));
+ list.add(serverMap.get(agentId));
return list;
}
-
+
return new ArrayList(serverMap.values());
}
+ // Private -------------------------------------------------------
+ private static MBeanServer createMBeanServer(String defaultDomain, boolean
registerServer)
+ {
+ String serverClass = System.getProperty("jbossmx.mbean.server.class",
"org.jboss.mx.server.MBeanServerImpl");
+
+ try
+ {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ Class clazz = cl.loadClass(serverClass);
+ Constructor constructor = clazz.getConstructor(new Class[] { String.class
});
+ MBeanServer server = (MBeanServer)constructor.newInstance(new Object[]
{defaultDomain});
+
+ if (registerServer)
+ {
+ String agentID = (String)server.getAttribute(
+ new
ObjectName("JMImplementation:type=MBeanServerDelegate"),
+ "MBeanServerId");
- private static String createAgentID() { return "BOOM!"; }
+ serverMap.put(agentID, server);
+ }
+ return server;
+ }
+ catch (MalformedObjectNameException e)
+ {
+ throw new Error(e.toString());
+ }
+ catch (JMException e)
+ {
+ throw new Error("Cannot retrieve AgentID: " + e.toString());
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new IllegalArgumentException("The MBean server implementation class
" + serverClass + " was not found: " + e.toString());
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new IllegalArgumentException("The MBean server implementation class
" + serverClass + " must contain a default domain string constructor: " + serverClass
+ "(java.langString defaultDomain)");
+ }
+ catch (InstantiationException e)
+ {
+ throw new IllegalArgumentException("Cannot instantiate class " +
serverClass + ": " + e.toString());
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new IllegalArgumentException("Unable to create the MBean server
instance. Illegal access to class " + serverClass + " constructor: " + e.toString());
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new RuntimeException("Unable to create the MBean server instance.
Class " + serverClass + " has raised an exception in constructor: " +
e.getTargetException().toString());
+ }
+ }
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development