Search in sources :

Example 26 with InstanceAlreadyExistsException

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

the class DefaultLoggingFactory method configure.

@Override
public void configure(MetricRegistry metricRegistry, String name) {
    LoggingUtil.hijackJDKLogging();
    CHANGE_LOGGER_CONTEXT_LOCK.lock();
    final Logger root;
    try {
        root = configureLoggers(name);
    } finally {
        CHANGE_LOGGER_CONTEXT_LOCK.unlock();
    }
    final LevelFilterFactory<ILoggingEvent> levelFilterFactory = new ThresholdLevelFilterFactory();
    final AsyncAppenderFactory<ILoggingEvent> asyncAppenderFactory = new AsyncLoggingEventAppenderFactory();
    final LayoutFactory<ILoggingEvent> layoutFactory = new DropwizardLayoutFactory();
    for (AppenderFactory<ILoggingEvent> output : appenders) {
        root.addAppender(output.build(loggerContext, name, layoutFactory, levelFilterFactory, asyncAppenderFactory));
    }
    StatusPrinter.setPrintStream(configurationErrorsStream);
    try {
        StatusPrinter.printIfErrorsOccured(loggerContext);
    } finally {
        StatusPrinter.setPrintStream(System.out);
    }
    final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    MBEAN_REGISTRATION_LOCK.lock();
    try {
        final ObjectName objectName = new ObjectName("io.dropwizard:type=Logging");
        if (!server.isRegistered(objectName)) {
            server.registerMBean(new JMXConfigurator(loggerContext, server, objectName), objectName);
        }
    } catch (MalformedObjectNameException | InstanceAlreadyExistsException | NotCompliantMBeanException | MBeanRegistrationException e) {
        throw new RuntimeException(e);
    } finally {
        MBEAN_REGISTRATION_LOCK.unlock();
    }
    configureInstrumentation(root, metricRegistry);
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) DropwizardLayoutFactory(io.dropwizard.logging.layout.DropwizardLayoutFactory) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) ThresholdLevelFilterFactory(io.dropwizard.logging.filter.ThresholdLevelFilterFactory) ObjectName(javax.management.ObjectName) AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) JMXConfigurator(ch.qos.logback.classic.jmx.JMXConfigurator) MBeanRegistrationException(javax.management.MBeanRegistrationException) MBeanServer(javax.management.MBeanServer)

Example 27 with InstanceAlreadyExistsException

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

the class MBeans method register.

/**
   * Register the MBean using our standard MBeanName format
   * "hadoop:service=<serviceName>,name=<nameName>"
   * Where the <serviceName> and <nameName> are the supplied parameters
   *
   * @param serviceName
   * @param nameName
   * @param theMbean - the MBean to register
   * @return the named used to register the MBean
   */
public static ObjectName register(String serviceName, String nameName, Object theMbean) {
    final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName name = getMBeanName(serviceName, nameName);
    if (name != null) {
        try {
            mbs.registerMBean(theMbean, name);
            LOG.debug("Registered " + name);
            return name;
        } catch (InstanceAlreadyExistsException iaee) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("Failed to register MBean \"" + name + "\"", iaee);
            } else {
                LOG.warn("Failed to register MBean \"" + name + "\": Instance already exists.");
            }
        } catch (Exception e) {
            LOG.warn("Failed to register MBean \"" + name + "\"", e);
        }
    }
    return null;
}
Also used : InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 28 with InstanceAlreadyExistsException

use of javax.management.InstanceAlreadyExistsException in project archaius by Netflix.

the class ConfigJMXManager method registerConfigMbean.

public static ConfigMBean registerConfigMbean(AbstractConfiguration config) {
    StandardMBean mbean = null;
    ConfigMBean bean = null;
    try {
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        bean = new BaseConfigMBean(config);
        mbean = new StandardMBean(bean, ConfigMBean.class);
        mbs.registerMBean(mbean, getJMXObjectName(config, bean));
    } catch (NotCompliantMBeanException e) {
        throw new RuntimeException("NotCompliantMBeanException", e);
    } catch (InstanceAlreadyExistsException e) {
        throw new RuntimeException("InstanceAlreadyExistsException", e);
    } catch (MBeanRegistrationException e) {
        throw new RuntimeException("MBeanRegistrationException", e);
    } catch (Exception e) {
        throw new RuntimeException("registerConfigMbeanException", e);
    }
    return bean;
}
Also used : StandardMBean(javax.management.StandardMBean) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanServer(javax.management.MBeanServer)

Example 29 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 30 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)

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