User: user57
Date: 01/07/19 22:08:56
Modified: src/main/org/jboss/util MBeanProxy.java
Log:
o cleaned up & added javadoc
o added methods that take a MBeanServer
o decoding a few more jmx exceptions
Revision Changes Path
1.6 +131 -36 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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- MBeanProxy.java 2001/06/18 20:01:28 1.5
+++ MBeanProxy.java 2001/07/20 05:08:56 1.6
@@ -6,23 +6,27 @@
*/
package org.jboss.util;
-import java.io.*;
-import java.net.*;
import java.lang.reflect.Method;
-import javax.management.*;
-import javax.management.loading.MLet;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+import javax.management.MalformedObjectNameException;
+import javax.management.MBeanException;
+import javax.management.ReflectionException;
+import javax.management.RuntimeOperationsException;
+import javax.management.RuntimeMBeanException;
+import javax.management.RuntimeErrorException;
-import org.jboss.logging.Log;
import org.jboss.proxy.Proxy;
import org.jboss.proxy.InvocationHandler;
/**
- * <description>
+ * A factory for producing MBean proxies.
*
- * @see <related>
- * @author <a href="mailto:[EMAIL PROTECTED]">Rickard �berg</a>.
- * @version $Revision: 1.5 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Rickard �berg</a>.
+ * @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a>
+ * @version $Revision: 1.6 $
*/
public class MBeanProxy
implements InvocationHandler
@@ -30,60 +34,151 @@
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
- ObjectName name;
- MBeanServer server;
+
+ /** The server to proxy invoke calls to. */
+ private final MBeanServer server;
+
+ /** The name of the object to invoke. */
+ private final ObjectName name;
// Static --------------------------------------------------------
- public static Object create(Class intf, String name)
+
+ /**
+ * Create an MBean proxy.
+ *
+ * @param intf The interface which the proxy will implement.
+ * @param name A string used to construct the ObjectName of the
+ * MBean to proxy to.
+ * @return A MBean proxy.
+ *
+ * @throws MalformedObjectNameException Invalid object name.
+ */
+ public static Object create(final Class intf, final String name)
+ throws MalformedObjectNameException
+ {
+ return Proxy.newProxyInstance(intf.getClassLoader(),
+ new Class[] { intf },
+ new MBeanProxy(new ObjectName(name)));
+ }
+
+ /**
+ * Create an MBean proxy.
+ *
+ * @param intf The interface which the proxy will implement.
+ * @param name A string used to construct the ObjectName of the
+ * MBean to proxy to.
+ * @param server The MBeanServer that contains the MBean to proxy to.
+ * @return A MBean proxy.
+ *
+ * @throws MalformedObjectNameException Invalid object name.
+ */
+ public static Object create(final Class intf,
+ final String name,
+ final MBeanServer server)
throws MalformedObjectNameException
{
+ return Proxy.newProxyInstance
+ (intf.getClassLoader(),
+ new Class[] { intf },
+ new MBeanProxy(new ObjectName(name), server));
+ }
+
+ /**
+ * Create an MBean proxy.
+ *
+ * @param intf The interface which the proxy will implement.
+ * @param name The name of the MBean to proxy invocations to.
+ * @return A MBean proxy.
+ */
+ public static Object create(final Class intf, final ObjectName name)
+ {
return Proxy.newProxyInstance(intf.getClassLoader(),
- new Class[] { intf },
- new MBeanProxy(name));
+ new Class[] { intf },
+ new MBeanProxy(name));
}
- public static Object create(Class intf, ObjectName name)
+ /**
+ * Create an MBean proxy.
+ *
+ * @param intf The interface which the proxy will implement.
+ * @param name The name of the MBean to proxy invocations to.
+ * @param server The MBeanServer that contains the MBean to proxy to.
+ * @return A MBean proxy.
+ */
+ public static Object create(final Class intf,
+ final ObjectName name,
+ final MBeanServer server)
{
return Proxy.newProxyInstance(intf.getClassLoader(),
- new Class[] { intf },
- new MBeanProxy(name));
+ new Class[] { intf },
+ new MBeanProxy(name, server));
}
// Constructors --------------------------------------------------
- MBeanProxy(String name)
- throws MalformedObjectNameException
+
+ /**
+ * Construct a MBeanProxy.
+ */
+ MBeanProxy(final ObjectName name)
{
- this(new ObjectName(name));
+ this(name, getServer());
}
- MBeanProxy(ObjectName name)
+ /**
+ * 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;
- server = (MBeanServer)
MBeanServerFactory.findMBeanServer(null).iterator().next();
+ this.server = server;
}
-
+
// Public --------------------------------------------------------
- public Object invoke(Object proxy,
- Method method,
- Object[] args)
- throws Throwable
+
+ /**
+ * 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++)
+ for (int i = 0; i < types.length; i++) {
sig[i] = types[i].getName();
-
- try
- {
+ }
+
+ // invoke the server and decode JMX exceptions
+ try {
return server.invoke(name, method.getName(), args, sig);
- } catch (MBeanException e)
- {
+ }
+ catch (MBeanException e) {
+ throw e.getTargetException();
+ }
+ catch (ReflectionException e) {
+ throw e.getTargetException();
+ }
+ catch (RuntimeOperationsException e) {
throw e.getTargetException();
- } catch (ReflectionException e)
- {
+ }
+ catch (RuntimeMBeanException e) {
throw e.getTargetException();
+ }
+ catch (RuntimeErrorException e) {
+ throw e.getTargetError();
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development