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);
}
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;
}
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;
}
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
}
}
}
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
}
}
}
Aggregations