Search in sources :

Example 1 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project tomcat by apache.

the class BaseGenericObjectPool method jmxRegister.

/**
     * Registers the pool with the platform MBean server.
     * The registered name will be
     * <code>jmxNameBase + jmxNamePrefix + i</code> where i is the least
     * integer greater than or equal to 1 such that the name is not already
     * registered. Swallows MBeanRegistrationException, NotCompliantMBeanException
     * returning null.
     *
     * @param config Pool configuration
     * @param jmxNameBase default base JMX name for this pool
     * @param jmxNamePrefix name prefix
     * @return registered ObjectName, null if registration fails
     */
private ObjectName jmxRegister(final BaseObjectPoolConfig config, final String jmxNameBase, String jmxNamePrefix) {
    ObjectName objectName = null;
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    int i = 1;
    boolean registered = false;
    String base = config.getJmxNameBase();
    if (base == null) {
        base = jmxNameBase;
    }
    while (!registered) {
        try {
            ObjectName objName;
            // only one so the names are cleaner.
            if (i == 1) {
                objName = new ObjectName(base + jmxNamePrefix);
            } else {
                objName = new ObjectName(base + jmxNamePrefix + i);
            }
            mbs.registerMBean(this, objName);
            objectName = objName;
            registered = true;
        } catch (final MalformedObjectNameException e) {
            if (BaseObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX.equals(jmxNamePrefix) && jmxNameBase.equals(base)) {
                // Shouldn't happen. Skip registration if it does.
                registered = true;
            } else {
                // Must be an invalid name. Use the defaults instead.
                jmxNamePrefix = BaseObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX;
                base = jmxNameBase;
            }
        } catch (final InstanceAlreadyExistsException e) {
            // Increment the index and try again
            i++;
        } catch (final MBeanRegistrationException e) {
            // Shouldn't happen. Skip registration if it does.
            registered = true;
        } catch (final NotCompliantMBeanException e) {
            // Shouldn't happen. Skip registration if it does.
            registered = true;
        }
    }
    return objectName;
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Example 2 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project hibernate-orm by hibernate.

the class EhcacheHibernateMBeanRegistrationImpl method registerBean.

private void registerBean(String name, CacheManager manager) throws Exception {
    ehcacheHibernate = new EhcacheHibernate(manager);
    int tries = 0;
    boolean success;
    Exception exception = null;
    final String cacheManagerClusterUUID = manager.getClusterUUID();
    String registeredCacheManagerName;
    do {
        registeredCacheManagerName = name;
        if (tries != 0) {
            registeredCacheManagerName += "_" + tries;
        }
        try {
            // register the CacheManager MBean
            final MBeanServer mBeanServer = getMBeanServer();
            cacheManagerObjectName = EhcacheHibernateMbeanNames.getCacheManagerObjectName(cacheManagerClusterUUID, registeredCacheManagerName);
            mBeanServer.registerMBean(ehcacheHibernate, cacheManagerObjectName);
            success = true;
            break;
        } catch (InstanceAlreadyExistsException e) {
            success = false;
            exception = e;
        }
        tries++;
    } while (tries < MAX_MBEAN_REGISTRATION_RETRIES);
    if (!success) {
        throw new Exception("Cannot register mbean for CacheManager with name" + manager.getName() + " afterQuery " + MAX_MBEAN_REGISTRATION_RETRIES + " retries. Last tried name=" + registeredCacheManagerName, exception);
    }
    status = Status.STATUS_ALIVE;
}
Also used : InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) CacheException(net.sf.ehcache.CacheException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanServer(javax.management.MBeanServer)

Example 3 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project jdk8u_jdk by JetBrains.

the class SameObjectTwoNamesTest method main.

public static void main(String[] args) throws Exception {
    boolean expectException = (System.getProperty("jmx.mxbean.multiname") == null);
    try {
        ObjectName objectName1 = new ObjectName("test:index=1");
        ObjectName objectName2 = new ObjectName("test:index=2");
        MBeanServer mbs = MBeanServerFactory.createMBeanServer();
        MXBC_SimpleClass01 mxBeanObject = new MXBC_SimpleClass01();
        mbs.registerMBean(mxBeanObject, objectName1);
        mbs.registerMBean(mxBeanObject, objectName2);
        if (expectException) {
            throw new Exception("TEST FAILED: " + "InstanceAlreadyExistsException was not thrown");
        } else
            System.out.println("Correctly got no exception with compat property");
    } catch (InstanceAlreadyExistsException e) {
        if (expectException) {
            System.out.println("Got expected InstanceAlreadyExistsException:");
            e.printStackTrace(System.out);
        } else {
            throw new Exception("TEST FAILED: Got exception even though compat property set", e);
        }
    }
    System.out.println("TEST PASSED");
}
Also used : InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Example 4 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project aries by apache.

the class MBeanHolder method register.

void register(final MBeanServer server) {
    ObjectInstance instance;
    try {
        instance = server.registerMBean(mbean, requestedObjectName);
        registrations.put(server, instance.getObjectName());
    } catch (InstanceAlreadyExistsException e) {
        log.error("register: Failure registering MBean " + mbean, e);
    } catch (MBeanRegistrationException e) {
        log.error("register: Failure registering MBean " + mbean, e);
    } catch (NotCompliantMBeanException e) {
        log.error("register: Failure registering MBean " + mbean, e);
    }
}
Also used : NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) ObjectInstance(javax.management.ObjectInstance) MBeanRegistrationException(javax.management.MBeanRegistrationException)

Example 5 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project datanucleus-rdbms by datanucleus.

the class BasicDataSource method jmxRegister.

private void jmxRegister() {
    // Return immediately if this DataSource has already been registered
    if (registeredJmxName != null) {
        return;
    }
    // Return immediately if no JMX name has been specified
    String requestedName = getJmxName();
    if (requestedName == null) {
        return;
    }
    ObjectName oname;
    try {
        oname = new ObjectName(requestedName);
    } catch (MalformedObjectNameException e) {
        log.warn("The requested JMX name [" + requestedName + "] was not valid and will be ignored.");
        return;
    }
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    try {
        mbs.registerMBean(this, oname);
    } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) {
        log.warn("Failed to complete JMX registration", e);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Aggregations

InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)116 ObjectName (javax.management.ObjectName)87 MBeanRegistrationException (javax.management.MBeanRegistrationException)73 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)70 MalformedObjectNameException (javax.management.MalformedObjectNameException)64 MBeanServer (javax.management.MBeanServer)48 InstanceNotFoundException (javax.management.InstanceNotFoundException)37 IOException (java.io.IOException)13 ObjectInstance (javax.management.ObjectInstance)12 Test (org.junit.Test)12 StandardMBean (javax.management.StandardMBean)9 MBeanException (javax.management.MBeanException)7 ReflectionException (javax.management.ReflectionException)7 HashMap (java.util.HashMap)5 JMRuntimeException (javax.management.JMRuntimeException)4 RuntimeOperationsException (javax.management.RuntimeOperationsException)4 MalformedURLException (java.net.MalformedURLException)3 AttributeNotFoundException (javax.management.AttributeNotFoundException)3 DynamicMBean (javax.management.DynamicMBean)3 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)3