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  Changes    Path
  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 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));
     }
  
     /**
      * 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, server));
     }
  }
  
  
  
  
  1.1                  jboss-common/src/main/org/jboss/util/jmx/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.jmx;
  
  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);
     }
  }
  
  
  
  1.1                  jboss-common/src/main/org/jboss/util/jmx/ObjectNameFactory.java
  
  Index: ObjectNameFactory.java
  ===================================================================
  /***************************************
   *                                     *
   *  JBoss: The OpenSource J2EE WebOS   *
   *                                     *
   *  Distributable under LGPL license.  *
   *  See terms of license at gnu.org.   *
   *                                     *
   ***************************************/
  
  package org.jboss.util.jmx;
  
  import java.util.Hashtable;
  
  import javax.management.MalformedObjectNameException;
  import javax.management.ObjectName;
  
  /**
   * A simple factory for creating safe object names.  This factory
   * will <b>not</b> throw MalformedObjectNameException.  Any such 
   * exceptions will be translated into Errors.
   *      
   * @author <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
   * @version $Revision: 1.1 $
   */
  public class ObjectNameFactory
  {
     public static ObjectName create(String name) {
        try {
         return new ObjectName(name);
        }
        catch (MalformedObjectNameException e) {
         throw new Error("Invalid ObjectName: " + name + "; " + e);
        }
     }
  
     public static ObjectName create(String domain, String key, String value) {
        try {
         return new ObjectName(domain, key, value);
        }
        catch (MalformedObjectNameException e) {
         throw new Error("Invalid ObjectName: " + domain + "," + key + "," + value + 
"; " + e);
        }
     }
  
     public static ObjectName create(String domain, Hashtable table) {
        try {
         return new ObjectName(domain, table);
        }
        catch (MalformedObjectNameException e) {
         throw new Error("Invalid ObjectName: " + domain + "," + table + "; " + e);
        }
     }
  }
  
  
  
  1.1                  jboss-common/src/main/org/jboss/util/jmx/package.html
  
  Index: package.html
  ===================================================================
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  <html>
    <head>
      <!-- $Id: package.html,v 1.1 2002/02/15 06:14:23 user57 Exp $ -->
      <!--
  
      JBoss: The OpenSource J2EE WebOS 
  
      Distributable under LGPL license.
      See terms of license at gnu.org.
  
      -->
    </head>
  
    <body bgcolor="white">
      <p>Utilities for the <em>Java Management Extentions</em> API.
  
      <h2>Package Specification</h2>
      <ul>
        <li><a href="javascript: alert('not available')">Not Available</a>
      </ul>
        
      <h2>Related Documentation</h2>
      <ul>
        <li><a href="javascript: alert('not available')">Not Available</a>
      </ul>
  
      <h2>Package Status</h2>
      <ul>
        <li><font color="green"><b>STABLE</b></font>
      </ul>
  
      <h2>Todo</h2>
      <ul>
        <li>???
      </ul>
  
      <!-- Put @see and @since tags down here. -->
  
    </body>
  </html>
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to