@ Override public ObjectInstance registerMBean ( Object object , ObjectName name ) throws MBeanRegistrationException , NotCompliantMBeanException { while ( true ) { try { // try to register the mbean return mbeanServer . registerMBean ( object , name ) ; } catch ( InstanceAlreadyExistsException ignored ) { } try { // a mbean is already installed, try to return the already registered instance ObjectInstance objectInstance = mbeanServer . getObjectInstance ( name ) ; log . debug ( "%s already bound to %s" , name , objectInstance ) ; return objectInstance ; } catch ( InstanceNotFoundException ignored ) { // the mbean was removed before we could get the reference // start the whole process over again } } }
Delegates to the wrapped mbean server but if a mbean is already registered with the specified name the existing instance is returned .