public String registerMBean ( Object bean , String name , boolean replace ) throws MalformedObjectNameException , NotCompliantMBeanException , MBeanRegistrationException { synchronized ( mBeanServer ) { ObjectName newBeanName = null ; try { newBeanName = new ObjectName ( name ) ; beansNames . add ( newBeanName ) ; // Saving bean name for possible later cleanups mBeanServer . registerMBean ( bean , newBeanName ) ; return name ; } catch ( InstanceAlreadyExistsException e ) { beansNames . remove ( newBeanName ) ; // Bean not registered, it name is not required for cleanup if ( replace ) { unregisterMBean ( name ) ; return registerMBean ( bean , name , true ) ; } else return registerMBean ( bean , resolveDuplicateName ( name ) ) ; } } }
Registers MBean in local MBean server .