Example usage for org.springframework.jmx.support RegistrationPolicy IGNORE_EXISTING

List of usage examples for org.springframework.jmx.support RegistrationPolicy IGNORE_EXISTING

Introduction

In this page you can find the example usage for org.springframework.jmx.support RegistrationPolicy IGNORE_EXISTING.

Prototype

RegistrationPolicy IGNORE_EXISTING

To view the source code for org.springframework.jmx.support RegistrationPolicy IGNORE_EXISTING.

Click Source Link

Document

Registration should ignore the affected MBean when attempting to register an MBean under a name that already exists.

Usage

From source file:com.predic8.membrane.core.jmx.JmxExporter.java

@Override
public void start() {
    exporter = new MBeanExporter();
    exporter.setRegistrationPolicy(RegistrationPolicy.IGNORE_EXISTING);
    MetadataMBeanInfoAssembler assembler = new MetadataMBeanInfoAssembler();
    assembler.setAttributeSource(new AnnotationJmxAttributeSource());
    assembler.afterPropertiesSet();//from  w w w .j a  va2 s. com
    exporter.setAssembler(assembler);
}

From source file:io.kahu.hawaii.config.KahuConfig.java

@Bean
public MBeanExporter mbeanExporter() throws ServerException {
    MBeanExporter mbeanExporter = new MBeanExporter();
    mbeanExporter.setServer(jolokiaServer());
    mbeanExporter.setRegistrationPolicy(RegistrationPolicy.IGNORE_EXISTING);
    Map<String, Object> beans = getMBeans();
    mbeanExporter.setBeans(beans);/*from  w w  w  . java  2  s . c om*/
    return mbeanExporter;
}

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//from   w w w  .j  a  v a2  s.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);
}