use of javax.management.ObjectInstance in project camel by apache.
the class DefaultManagementAgentMockTest method testObjectNameModification.
@Test
public void testObjectNameModification() throws JMException {
MBeanServer mbeanServer = createStrictMock(MBeanServer.class);
ObjectInstance instance = createStrictMock(ObjectInstance.class);
ManagementAgent agent = new DefaultManagementAgent();
agent.setMBeanServer(mbeanServer);
Object object = "object";
ObjectName sourceObjectName = new ObjectName("domain", "key", "value");
ObjectName registeredObjectName = new ObjectName("domain", "key", "otherValue");
// Register MBean and return different ObjectName
expect(mbeanServer.isRegistered(sourceObjectName)).andReturn(false);
expect(mbeanServer.registerMBean(object, sourceObjectName)).andReturn(instance);
expect(instance.getObjectName()).andReturn(registeredObjectName);
expect(mbeanServer.isRegistered(registeredObjectName)).andReturn(true);
replay(mbeanServer, instance);
agent.register(object, sourceObjectName);
assertTrue(agent.isRegistered(sourceObjectName));
verify(mbeanServer, instance);
reset(mbeanServer, instance);
// ... and unregister it again
expect(mbeanServer.isRegistered(registeredObjectName)).andReturn(true);
mbeanServer.unregisterMBean(registeredObjectName);
expect(mbeanServer.isRegistered(sourceObjectName)).andReturn(false);
replay(mbeanServer);
agent.unregister(sourceObjectName);
assertFalse(agent.isRegistered(sourceObjectName));
verify(mbeanServer);
}
use of javax.management.ObjectInstance 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.ObjectInstance 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.ObjectInstance in project spring-boot by spring-projects.
the class InfinispanCacheStatisticsProvider method getObjectName.
@Override
protected ObjectName getObjectName(SpringCache cache) throws MalformedObjectNameException {
ObjectName name = new ObjectName("org.infinispan:component=Statistics,type=Cache,name=\"" + cache.getName() + "(local)\",*");
Set<ObjectInstance> instances = getMBeanServer().queryMBeans(name, null);
if (instances.size() == 1) {
return instances.iterator().next().getObjectName();
}
// None or more than one
return null;
}
use of javax.management.ObjectInstance in project spring-boot by spring-projects.
the class SpringApplicationAdminJmxAutoConfigurationTests method registeredWithProperty.
@Test
public void registeredWithProperty() throws Exception {
load(ENABLE_ADMIN_PROP);
ObjectName objectName = createDefaultObjectName();
ObjectInstance objectInstance = this.mBeanServer.getObjectInstance(objectName);
assertThat(objectInstance).as("Lifecycle bean should have been registered").isNotNull();
}
Aggregations