in src/main/java/org/apache/commons/pool3/impl/BaseGenericObjectPool.java [1150:1198]
private ObjectName jmxRegister(final BaseObjectPoolConfig<T> config,
final String jmxNameBase, String jmxNamePrefix) {
ObjectName newObjectName = 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;
// Skip the numeric suffix for the first pool in case there is
// only one so the names are cleaner.
if (i == 1) {
objName = new ObjectName(base + jmxNamePrefix);
} else {
objName = new ObjectName(base + jmxNamePrefix + i);
}
if (!mbs.isRegistered(objName)) {
mbs.registerMBean(this, objName);
newObjectName = objName;
registered = true;
} else {
// Increment the index and try again
i++;
}
} 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 | NotCompliantMBeanException e) {
// Shouldn't happen. Skip registration if it does.
registered = true;
}
}
return newObjectName;
}