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