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