[JBoss-dev] CVS update: jboss-common/src/main/org/jboss/util/jmx MBeanProxy.java
User: lqd Date: 02/04/08 02:35:31 Modified:src/main/org/jboss/util/jmx MBeanProxy.java Log: fix compilation issues when using jikes Revision ChangesPath 1.5 +8 -6 jboss-common/src/main/org/jboss/util/jmx/MBeanProxy.java Index: MBeanProxy.java === RCS file: /cvsroot/jboss/jboss-common/src/main/org/jboss/util/jmx/MBeanProxy.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- MBeanProxy.java 3 Apr 2002 08:15:08 - 1.4 +++ MBeanProxy.java 8 Apr 2002 09:35:30 - 1.5 @@ -37,7 +37,7 @@ * liDon't process attributes using invoke. * /ul * - * @version tt$Revision: 1.4 $/tt + * @version tt$Revision: 1.5 $/tt * @author a href=mailto:[EMAIL PROTECTED];Rickard Öberg/a. * @author a href=mailto:[EMAIL PROTECTED];Jason Dillon/a * @author a href=mailto:[EMAIL PROTECTED];Adrian Brock/a. @@ -260,15 +260,15 @@ // make a which delegates to MBeanProxyInstance's cl for it's class resolution ClassLoader cl = new ClassLoader(intf.getClassLoader()) { - public Class loadClass(final String name) throws ClassNotFoundException + public Class loadClass(final String className) throws ClassNotFoundException { try { - return super.loadClass(name); + return super.loadClass(className); } catch (ClassNotFoundException e) { // only allow loading of MBeanProxyInstance from this loader - if (name.equals(MBeanProxyInstance.class.getName())) { - return MBeanProxyInstance.class.getClassLoader().loadClass(name); + if (className.equals(MBeanProxyInstance.class.getName())) { + return MBeanProxyInstance.class.getClassLoader().loadClass(className); } // was some other classname, throw the CNFE @@ -282,4 +282,6 @@ new MBeanProxy(name, server)); } } - +/* +vim:tabstop=3:et:shiftwidth=3 +*/ ___ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
[JBoss-dev] CVS update: jboss-common/src/main/org/jboss/util/jmx MBeanProxy.java
User: ejort Date: 02/03/23 13:11:00 Modified:src/main/org/jboss/util/jmx MBeanProxy.java Log: JBoss/JBossMX integration. Also includes a fix to the cluster tests and a more complete ejblink test that currently fails Revision ChangesPath 1.3 +99 -3 jboss-common/src/main/org/jboss/util/jmx/MBeanProxy.java Index: MBeanProxy.java === RCS file: /cvsroot/jboss/jboss-common/src/main/org/jboss/util/jmx/MBeanProxy.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MBeanProxy.java 5 Mar 2002 02:59:52 - 1.2 +++ MBeanProxy.java 23 Mar 2002 21:11:00 - 1.3 @@ -13,16 +13,29 @@ import java.lang.reflect.Proxy; import java.lang.reflect.InvocationHandler; +import java.util.HashMap; + +import javax.management.Attribute; +import javax.management.InstanceNotFoundException; +import javax.management.MBeanAttributeInfo; +import javax.management.MBeanInfo; import javax.management.MBeanServer; import javax.management.ObjectName; import javax.management.MalformedObjectNameException; /** * A factory for producing MBean proxies. - * + * + * pbRevisions:/b + * pb20020321 Adrian Brock:/b + * ul + * liDon't process attributes using invoke. + * /ul + * * @author a href=mailto:[EMAIL PROTECTED];Rickard Öberg/a. * @author a href=mailto:[EMAIL PROTECTED];Jason Dillon/a - * @version $Revision: 1.2 $ + * @author a href=mailto:[EMAIL PROTECTED];Adrian Brock/a. + * @version $Revision: 1.3 $ */ public class MBeanProxy implements InvocationHandler @@ -32,6 +45,9 @@ /** The name of the object to invoke. */ private final ObjectName name; + + /** The MBean's attributes */ + private HashMap attributeMap = new HashMap(); /** * Construct a MBeanProxy. @@ -48,6 +64,20 @@ { this.name = name; this.server = server; + + // The MBean's attributes + try + { + MBeanInfo info = server.getMBeanInfo(name); + MBeanAttributeInfo[] attributes = info.getAttributes(); + + for (int i = 0; i attributes.length; ++i) +attributeMap.put(attributes[i].getName(), attributes[i]); + } + catch (Exception e) + { + throw new RuntimeException(Error creating MBeanProxy: + name); + } } /** @@ -59,6 +89,72 @@ Object[] args) throws Throwable { + String methodName = method.getName(); + + // Get attribute + if (methodName.startsWith(get) args == null) + { + String attrName = methodName.substring(3); + MBeanAttributeInfo info = (MBeanAttributeInfo) attributeMap.get(attrName); + if (info != null) + { +String retType = method.getReturnType().getName(); +if (retType.equals(info.getType())) +{ + try + { + return server.getAttribute(name, attrName); + } + catch (Exception e) + { + throw JMXExceptionDecoder.decode(e); + } +} + } + } + + // Is attribute + else if (methodName.startsWith(is) args == null) + { + String attrName = methodName.substring(2); + MBeanAttributeInfo info = (MBeanAttributeInfo) attributeMap.get(attrName); + if (info != null info.isIs()) + { +Class retType = method.getReturnType(); +if (retType.equals(Boolean.class) || retType.equals(Boolean.TYPE)) +{ + try + { + return server.getAttribute(name, attrName); + } + catch (Exception e) + { + throw JMXExceptionDecoder.decode(e); + } +} + } + } + + // Set attribute + else if (methodName.startsWith(set) args != null args.length == 1) + { + String attrName = methodName.substring(3); + MBeanAttributeInfo info = (MBeanAttributeInfo) attributeMap.get(attrName); + if (info != null method.getReturnType() == Void.TYPE) + { +try +{ + server.setAttribute(name, new Attribute(attrName, args[0])); + return null; +} +catch (Exception e) +{ + throw JMXExceptionDecoder.decode(e); +} + } + } + + // Operation if (args == null) args = new Object[0]; // convert the parameter types to strings for JMX @@ -70,7 +166,7 @@ // invoke the server
[JBoss-dev] CVS update: jboss-common/src/main/org/jboss/util/jmx MBeanProxy.java MBeanServerLocator.java ObjectNameFactory.java package.html
User: user57 Date: 02/02/14 22:14:23 Added: src/main/org/jboss/util/jmx MBeanProxy.java MBeanServerLocator.java ObjectNameFactory.java package.html Log: o importing the useful bits from the bliss cl. o plus some bits from server/*/util/* have been moved to util.jmx Revision ChangesPath 1.1 jboss-common/src/main/org/jboss/util/jmx/MBeanProxy.java Index: MBeanProxy.java === /*** * * * JBoss: The OpenSource J2EE WebOS * * * * Distributable under LGPL license. * * See terms of license at gnu.org. * * * ***/ package org.jboss.util.jmx; import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.lang.reflect.InvocationHandler; import javax.management.MBeanServer; 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; /** * A factory for producing MBean proxies. * * @author a href=mailto:[EMAIL PROTECTED];Rickard Öberg/a. * @author a href=mailto:[EMAIL PROTECTED];Jason Dillon/a * @version $Revision: 1.1 $ */ public class MBeanProxy implements InvocationHandler { /** The server to proxy invoke calls to. */ private final MBeanServer server; /** The name of the object to invoke. */ private final ObjectName name; /** * 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. * * @param intfThe interface which the proxy will implement. * @param nameA string used to construct the ObjectName of the *MBean to proxy to. * @returnA MBean proxy. * * @throws MalformedObjectNameExceptionInvalid 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 serverThe MBeanServer that contains the MBean to proxy to. * @return A MBean proxy. * * @throws MalformedObjectNameExceptionInvalid object name. */ public static Object create(final Class intf, final String name, final