List of usage examples for org.springframework.jmx.support RegistrationPolicy REPLACE_EXISTING
RegistrationPolicy REPLACE_EXISTING
To view the source code for org.springframework.jmx.support RegistrationPolicy REPLACE_EXISTING.
Click Source Link
From source file:org.springframework.jmx.support.MBeanRegistrationSupport.java
/** * Actually register the MBean with the server. The behavior when encountering * an existing MBean can be configured using {@link #setRegistrationPolicy}. * @param mbean the MBean instance// w w w .j a v a 2s .c om * @param objectName the suggested ObjectName for the MBean * @throws JMException if the registration failed */ protected void doRegister(Object mbean, ObjectName objectName) throws JMException { Assert.state(this.server != null, "No MBeanServer set"); ObjectName actualObjectName; synchronized (this.registeredBeans) { ObjectInstance registeredBean = null; try { registeredBean = this.server.registerMBean(mbean, objectName); } catch (InstanceAlreadyExistsException ex) { if (this.registrationPolicy == RegistrationPolicy.IGNORE_EXISTING) { if (logger.isDebugEnabled()) { logger.debug("Ignoring existing MBean at [" + objectName + "]"); } } else if (this.registrationPolicy == RegistrationPolicy.REPLACE_EXISTING) { try { if (logger.isDebugEnabled()) { logger.debug("Replacing existing MBean at [" + objectName + "]"); } this.server.unregisterMBean(objectName); registeredBean = this.server.registerMBean(mbean, objectName); } catch (InstanceNotFoundException ex2) { logger.error("Unable to replace existing MBean at [" + objectName + "]", ex2); throw ex; } } else { throw ex; } } // Track registration and notify listeners. actualObjectName = (registeredBean != null ? registeredBean.getObjectName() : null); if (actualObjectName == null) { actualObjectName = objectName; } this.registeredBeans.add(actualObjectName); } onRegister(actualObjectName, mbean); }