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 .