User: user57
Date: 02/02/12 20:26:40
Modified: src/main/org/jboss/util MBeanProxy.java
Added: src/main/org/jboss/util MBeanServerLocator.java
Log:
o These are all kinda related, so I am commiting them together
o This is the second half of the migration to using ObjectName OBJECT_NAME
o Not using jboss.system.* properties anywhere (one place in testsuite
which I am ignoring for now)
o StateManager will now read its config from a url (configURL), and only
attempt to write it back out if that is a file URL. Need to fix this
to not need to write back to a config file.
o Still setting jboss.home & jboss.system.home, but use ServerConfigMBean
to get the proper bits, will eventually abstract all file access out
o Added a simple locator to find a mbean server. This is trivial code,
but helps clean up client code and makes it obvious what it does.
Revision Changes Path
1.9 +61 -77 jboss/src/main/org/jboss/util/MBeanProxy.java
Index: MBeanProxy.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/util/MBeanProxy.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- MBeanProxy.java 7 Dec 2001 17:53:39 -0000 1.8
+++ MBeanProxy.java 13 Feb 2002 04:26:40 -0000 1.9
@@ -9,7 +9,6 @@
import java.lang.reflect.Method;
import javax.management.MBeanServer;
-import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import javax.management.MalformedObjectNameException;
import javax.management.MBeanException;
@@ -26,22 +25,77 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Rickard �berg</a>.
* @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
- * @version $Revision: 1.8 $
+ * @version $Revision: 1.9 $
*/
public class MBeanProxy
implements InvocationHandler
{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
/** The server to proxy invoke calls to. */
private final MBeanServer server;
/** The name of the object to invoke. */
private final ObjectName name;
- // Static --------------------------------------------------------
+ /**
+ * Construct a MBeanProxy.
+ */
+ MBeanProxy(final ObjectName name)
+ {
+ this(name, MBeanServerLocator.locate());
+ }
+
+ /**
+ * Construct a MBeanProxy.
+ */
+ MBeanProxy(final ObjectName name, final MBeanServer server)
+ {
+ this.name = name;
+ this.server = server;
+ }
+
+ /**
+ * Invoke the configured MBean via the target MBeanServer and decode
+ * any resulting JMX exceptions that are thrown.
+ */
+ public Object invoke(final Object proxy,
+ final Method method,
+ Object[] args)
+ throws Throwable
+ {
+ if (args == null) args = new Object[0];
+
+ // convert the parameter types to strings for JMX
+ Class[] types = method.getParameterTypes();
+ String[] sig = new String[types.length];
+ for (int i = 0; i < types.length; i++) {
+ sig[i] = types[i].getName();
+ }
+
+ // invoke the server and decode JMX exceptions
+ try {
+ return server.invoke(name, method.getName(), args, sig);
+ }
+ catch (MBeanException e) {
+ throw e.getTargetException();
+ }
+ catch (ReflectionException e) {
+ throw e.getTargetException();
+ }
+ catch (RuntimeOperationsException e) {
+ throw e.getTargetException();
+ }
+ catch (RuntimeMBeanException e) {
+ throw e.getTargetException();
+ }
+ catch (RuntimeErrorException e) {
+ throw e.getTargetError();
+ }
+ }
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Factory Methods //
+ ///////////////////////////////////////////////////////////////////////////
/**
* Create an MBean proxy.
@@ -113,75 +167,5 @@
new Class[] { intf },
new MBeanProxy(name, server));
}
-
- // Constructors --------------------------------------------------
-
- /**
- * Construct a MBeanProxy.
- */
- MBeanProxy(final ObjectName name)
- {
- this(name, getServer());
- }
-
- /**
- * Find the first MBeanServer.
- */
- private static MBeanServer getServer() {
- return (MBeanServer)
- MBeanServerFactory.findMBeanServer(null).iterator().next();
- }
-
- /**
- * Construct a MBeanProxy.
- */
- MBeanProxy(final ObjectName name, final MBeanServer server)
- {
- this.name = name;
- this.server = server;
- }
-
- // Public --------------------------------------------------------
-
- /**
- * Invoke the configured MBean via the target MBeanServer and decode
- * any resulting JMX exceptions that are thrown.
- */
- public Object invoke(final Object proxy,
- final Method method,
- Object[] args)
- throws Throwable
- {
- if (args == null) args = new Object[0];
-
- // convert the parameter types to strings for JMX
- Class[] types = method.getParameterTypes();
- String[] sig = new String[types.length];
- for (int i = 0; i < types.length; i++) {
- sig[i] = types[i].getName();
- }
-
- // invoke the server and decode JMX exceptions
- try {
- return server.invoke(name, method.getName(), args, sig);
- }
- catch (MBeanException e) {
- throw e.getTargetException();
- }
- catch (ReflectionException e) {
- throw e.getTargetException();
- }
- catch (RuntimeOperationsException e) {
- throw e.getTargetException();
- }
- catch (RuntimeMBeanException e) {
- throw e.getTargetException();
- }
- catch (RuntimeErrorException e) {
- throw e.getTargetError();
- }
- }
-
- // Protected -----------------------------------------------------
}
1.1 jboss/src/main/org/jboss/util/MBeanServerLocator.java
Index: MBeanServerLocator.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.util;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
/**
* A helper class to locate a MBeanServer.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
* @version $Revision: 1.1 $
*/
public class MBeanServerLocator
{
public static MBeanServer locate(final String agentID) {
MBeanServer server = (MBeanServer)
MBeanServerFactory.findMBeanServer(agentID).iterator().next();
return server;
}
public static MBeanServer locate() {
return locate(null);
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development