Search in sources :

Example 1 with MBeanRegistrationException

use of javax.management.MBeanRegistrationException 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 MBeanRegistrationException

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

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
    final String requestedName = getJmxName();
    if (requestedName == null) {
        return;
    }
    ObjectName oname;
    try {
        oname = new ObjectName(requestedName);
    } catch (final MalformedObjectNameException e) {
        log.warn("The requested JMX name [" + requestedName + "] was not valid and will be ignored.");
        return;
    }
    final 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)

Example 3 with MBeanRegistrationException

use of javax.management.MBeanRegistrationException in project sonarqube by SonarSource.

the class Jmx method register.

/**
   * Register a MBean to JMX server
   */
public static void register(String name, Object instance) {
    try {
        Class mbeanInterface = guessMBeanInterface(instance);
        ManagementFactory.getPlatformMBeanServer().registerMBean(new StandardMBean(instance, mbeanInterface), new ObjectName(name));
    } catch (MalformedObjectNameException | NotCompliantMBeanException | InstanceAlreadyExistsException | MBeanRegistrationException e) {
        throw new IllegalStateException("Can not register MBean [" + name + "]", e);
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) StandardMBean(javax.management.StandardMBean) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Example 4 with MBeanRegistrationException

use of javax.management.MBeanRegistrationException in project databus by linkedin.

the class OpenReplicatorEventProducer method shutdown.

/* (non-Javadoc)
   * @see com.linkedin.databus2.producers.AbstractEventProducer#shutdown()
   */
@Override
public synchronized void shutdown() {
    _producerThread.shutdown();
    super.shutdown();
    for (ObjectName name : _registeredMbeans) {
        try {
            _mbeanServer.unregisterMBean(name);
            _log.info("Unregistered or-source mbean: " + name);
        } catch (MBeanRegistrationException e) {
            _log.warn("Exception when unregistering or-source statistics mbean: " + name + e);
        } catch (InstanceNotFoundException e) {
            _log.warn("Exception when unregistering or-source statistics mbean: " + name + e);
        }
    }
}
Also used : InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Example 5 with MBeanRegistrationException

use of javax.management.MBeanRegistrationException in project databus by linkedin.

the class OracleEventProducer method shutdown.

@Override
public synchronized void shutdown() {
    for (ObjectName name : _registeredMbeans) {
        try {
            _mbeanServer.unregisterMBean(name);
            _log.info("Unregistered source mbean: " + name);
        } catch (MBeanRegistrationException e) {
            _log.warn("Exception when unregistering source statistics mbean: " + name + e);
        } catch (InstanceNotFoundException e) {
            _log.warn("Exception when unregistering source statistics mbean: " + name + e);
        }
    }
    super.shutdown();
}
Also used : InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanRegistrationException(javax.management.MBeanRegistrationException) ObjectName(javax.management.ObjectName)

Aggregations

MBeanRegistrationException (javax.management.MBeanRegistrationException)48 ObjectName (javax.management.ObjectName)39 MalformedObjectNameException (javax.management.MalformedObjectNameException)35 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)31 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)29 InstanceNotFoundException (javax.management.InstanceNotFoundException)21 MBeanServer (javax.management.MBeanServer)20 StandardMBean (javax.management.StandardMBean)8 IOException (java.io.IOException)7 RuntimeOperationsException (javax.management.RuntimeOperationsException)5 MalformedURLException (java.net.MalformedURLException)4 JMRuntimeException (javax.management.JMRuntimeException)3 MBeanException (javax.management.MBeanException)3 ObjectInstance (javax.management.ObjectInstance)3 PrivilegedActionException (java.security.PrivilegedActionException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ReflectionException (javax.management.ReflectionException)2 Test (org.junit.Test)2 Logger (ch.qos.logback.classic.Logger)1