src/main/java/org/lazydog/mbean/utility/RemoteMBeanInvocationHandler.java
@SuppressWarnings("unchecked")
    public static <T> T getMBean(Class<T> interfaceClass, ObjectName objectName, Properties environment) throws MBeanException {

        JMXConnector connector = null;

        // Get the JMX environment properties.
        String host = getProperty(environment, MBeanUtility.JMX_HOST_KEY);
        String port = getProperty(environment, MBeanUtility.JMX_PORT_KEY);
        String login = getProperty(environment, MBeanUtility.JMX_LOGIN_KEY);
        String password = getProperty(environment, MBeanUtility.JMX_PASSWORD_KEY);

        try {

            // Connect to the JMX service.
            connector = connect(host, port, login, password);

            // Connect to the MBean server.
            MBeanServerConnection mBeanServerConnection = connector.getMBeanServerConnection();

            // Validate the MBean.
            MBeanUtility.validateMBean(interfaceClass, objectName, mBeanServerConnection);
        } catch (IOException e) {
            throw new MBeanException(e,
                    "Unable to create the MBean represented by the interface class " +
                    interfaceClass.getName() + " and object name " +
                    objectName.getCanonicalName() + ".");
        } finally {
            close(connector);
        }

        // Create the MBean.
        return (T)Proxy.newProxyInstance(
                interfaceClass.getClassLoader(),
                new Class[]{interfaceClass},
                new RemoteMBeanInvocationHandler<T>(interfaceClass, objectName, host, port, login, password));
    }
@SuppressWarnings("unchecked")
    public static <T> T getMBean(Class<T> interfaceClass, ObjectName objectName, Properties environment) throws MBeanException {

        JMXConnector connector = null;

        // Get the JMX environment properties.
        String host = getProperty(environment, MBeanUtility.JMX_HOST_KEY);
        String port = getProperty(environment, MBeanUtility.JMX_PORT_KEY);
        String login = getProperty(environment, MBeanUtility.JMX_LOGIN_KEY);
        String password = getProperty(environment, MBeanUtility.JMX_PASSWORD_KEY);

        try {

            // Connect to the JMX service.
            connector = connect(host, port, login, password);

            // Connect to the MBean server.
            MBeanServerConnection mBeanServerConnection = connector.getMBeanServerConnection();

            // Validate the MBean.
            MBeanUtility.validateMBean(interfaceClass, objectName, mBeanServerConnection);
        } catch (IOException e) {
            throw new MBeanException(e,
                    "Unable to create the MBean represented by the interface class " +
                    interfaceClass.getName() + " and object name " +
                    objectName.getCanonicalName() + ".");
        } finally {
            close(connector);
        }

        // Create the MBean.
        return (T)Proxy.newProxyInstance(
                interfaceClass.getClassLoader(),
                new Class[]{interfaceClass},
                new RemoteMBeanInvocationHandler<T>(interfaceClass, objectName, host, port, login, password));
    }
@ SuppressWarnings ( "unchecked" ) public static < T > T getMBean ( Class < T > interfaceClass , ObjectName objectName , Properties environment ) throws MBeanException { JMXConnector connector = null ; // Get the JMX environment properties. String host = getProperty ( environment , MBeanUtility . JMX_HOST_KEY ) ; String port = getProperty ( environment , MBeanUtility . JMX_PORT_KEY ) ; String login = getProperty ( environment , MBeanUtility . JMX_LOGIN_KEY ) ; String password = getProperty ( environment , MBeanUtility . JMX_PASSWORD_KEY ) ; try { // Connect to the JMX service. connector = connect ( host , port , login , password ) ; // Connect to the MBean server. MBeanServerConnection mBeanServerConnection = connector . getMBeanServerConnection ( ) ; // Validate the MBean. MBeanUtility . validateMBean ( interfaceClass , objectName , mBeanServerConnection ) ; } catch ( IOException e ) { throw new MBeanException ( e , "Unable to create the MBean represented by the interface class " + interfaceClass . getName ( ) + " and object name " + objectName . getCanonicalName ( ) + "." ) ; } finally { close ( connector ) ; } // Create the MBean. return ( T ) Proxy . newProxyInstance ( interfaceClass . getClassLoader ( ) , new Class [ ] { interfaceClass } , new RemoteMBeanInvocationHandler < T > ( interfaceClass , objectName , host , port , login , password ) ) ; }
Get the MBean represented by the interface class and object name.

@param  interfaceClass  the MBean interface class.
@param  objectName      the MBean object name.
@param  environment     the JMX environment properties.

@return  the MBean.

@throws  MBeanException  if unable to get the MBean.
Get the MBean represented by the interface class and object name .