Search in sources :

Example 6 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project presto by prestodb.

the class RebindSafeMBeanServer method registerMBean.

/**
     * Delegates to the wrapped mbean server, but if a mbean is already registered
     * with the specified name, the existing instance is returned.
     */
@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
        }
    }
}
Also used : InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ObjectInstance(javax.management.ObjectInstance)

Example 7 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project presto by prestodb.

the class RebindSafeMBeanServer method registerMBean.

/**
     * Delegates to the wrapped mbean server, but if a mbean is already registered
     * with the specified name, the existing instance is returned.
     */
@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
        }
    }
}
Also used : InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ObjectInstance(javax.management.ObjectInstance)

Example 8 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project quasar by puniverse.

the class SimpleMBean method registerMBean.

protected void registerMBean() {
    try {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        ObjectName mxbeanName = new ObjectName(name);
        mbs.registerMBean(this, mxbeanName);
        this.registered = true;
    } catch (InstanceAlreadyExistsException ex) {
        throw new RuntimeException(ex);
    } catch (MBeanRegistrationException ex) {
        ex.printStackTrace();
    } catch (NotCompliantMBeanException ex) {
        throw new AssertionError(ex);
    } catch (MalformedObjectNameException ex) {
        throw new AssertionError(ex);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 9 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project redisson by redisson.

the class JCacheManager method enableManagement.

@Override
public void enableManagement(String cacheName, boolean enabled) {
    checkNotClosed();
    if (cacheName == null) {
        throw new NullPointerException();
    }
    JCache<?, ?> cache = caches.get(cacheName);
    if (cache == null) {
        throw new NullPointerException();
    }
    if (enabled) {
        JCacheManagementMXBean statBean = managementBeans.get(cache);
        if (statBean == null) {
            statBean = new JCacheManagementMXBean(cache);
            JCacheManagementMXBean oldBean = managementBeans.putIfAbsent(cache, statBean);
            if (oldBean != null) {
                statBean = oldBean;
            }
        }
        try {
            ObjectName objectName = queryNames("Configuration", cache);
            if (mBeanServer.queryNames(objectName, null).isEmpty()) {
                mBeanServer.registerMBean(statBean, objectName);
            }
        } catch (MalformedObjectNameException e) {
            throw new CacheException(e);
        } catch (InstanceAlreadyExistsException e) {
            throw new CacheException(e);
        } catch (MBeanRegistrationException e) {
            throw new CacheException(e);
        } catch (NotCompliantMBeanException e) {
            throw new CacheException(e);
        }
    } else {
        unregisterManagementBean(cache);
    }
    cache.getConfiguration(JCacheConfiguration.class).setManagementEnabled(enabled);
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) JCacheConfiguration(org.redisson.jcache.configuration.JCacheConfiguration) CacheException(javax.cache.CacheException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) JCacheManagementMXBean(org.redisson.jcache.bean.JCacheManagementMXBean) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Example 10 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project spring-framework by spring-projects.

the class MBeanRegistrationSupport method doRegister.

/**
	 * 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
	 * @param objectName the suggested ObjectName for the MBean
	 * @throws JMException if the registration failed
	 */
protected void doRegister(Object mbean, ObjectName objectName) throws JMException {
    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);
}
Also used : InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ObjectInstance(javax.management.ObjectInstance) ObjectName(javax.management.ObjectName)

Aggregations

InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)49 ObjectName (javax.management.ObjectName)38 MalformedObjectNameException (javax.management.MalformedObjectNameException)30 MBeanRegistrationException (javax.management.MBeanRegistrationException)29 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)28 MBeanServer (javax.management.MBeanServer)25 InstanceNotFoundException (javax.management.InstanceNotFoundException)14 ObjectInstance (javax.management.ObjectInstance)8 IOException (java.io.IOException)6 StandardMBean (javax.management.StandardMBean)6 Test (org.junit.Test)3 MalformedURLException (java.net.MalformedURLException)2 CacheException (javax.cache.CacheException)2 JMRuntimeException (javax.management.JMRuntimeException)2 MBeanException (javax.management.MBeanException)2 ReflectionException (javax.management.ReflectionException)2 RuntimeOperationsException (javax.management.RuntimeOperationsException)2 Logger (ch.qos.logback.classic.Logger)1 JMXConfigurator (ch.qos.logback.classic.jmx.JMXConfigurator)1 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1