src/main/java/org/lazydog/mbean/utility/MBeanUtility.java
public static <T> ObjectName register(Class<T> interfaceClass, ObjectName objectName) throws MBeanException {

        // Check if the interface class is valid.
        if (interfaceClass == null) {
            throw new IllegalArgumentException("The interface class is invalid.");
        }

        try {

            // Get the MBean server.
            MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();

            // Check if the MBean is not registered with the MBean server.
            if (!mBeanServer.isRegistered(objectName)) {

                // Register the MBean with the MBean server.
                ObjectInstance objectInstance = mBeanServer.registerMBean(createObject(interfaceClass), objectName);

                // Get the object name for the registered MBean.
                objectName = objectInstance.getObjectName();
            }
        } catch (Exception e) {
            throw new MBeanException(e, "Unable to register the MBean.");
        }

        return objectName;
    }
public static <T> ObjectName register(Class<T> interfaceClass, ObjectName objectName) throws MBeanException {

        // Check if the interface class is valid.
        if (interfaceClass == null) {
            throw new IllegalArgumentException("The interface class is invalid.");
        }

        try {

            // Get the MBean server.
            MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();

            // Check if the MBean is not registered with the MBean server.
            if (!mBeanServer.isRegistered(objectName)) {

                // Register the MBean with the MBean server.
                ObjectInstance objectInstance = mBeanServer.registerMBean(createObject(interfaceClass), objectName);

                // Get the object name for the registered MBean.
                objectName = objectInstance.getObjectName();
            }
        } catch (Exception e) {
            throw new MBeanException(e, "Unable to register the MBean.");
        }

        return objectName;
    }
public static < T > ObjectName register ( Class < T > interfaceClass , ObjectName objectName ) throws MBeanException { // Check if the interface class is valid. if ( interfaceClass == null ) { throw new IllegalArgumentException ( "The interface class is invalid." ) ; } try { // Get the MBean server. MBeanServer mBeanServer = ManagementFactory . getPlatformMBeanServer ( ) ; // Check if the MBean is not registered with the MBean server. if ( ! mBeanServer . isRegistered ( objectName ) ) { // Register the MBean with the MBean server. ObjectInstance objectInstance = mBeanServer . registerMBean ( createObject ( interfaceClass ) , objectName ) ; // Get the object name for the registered MBean. objectName = objectInstance . getObjectName ( ) ; } } catch ( Exception e ) { throw new MBeanException ( e , "Unable to register the MBean." ) ; } return objectName ; }
Register the MBean represented by the interface class.

@param  interfaceClass  the MBean interface class.
@param  objectName      the MBean object name.

@return  the MBean object name.

@throws  IllegalArgumentException  if the interface class is invalid.
@throws  MBeanException            if unable to register the MBean.
Register the MBean represented by the interface class .