List of usage examples for javax.management ObjectInstance ObjectInstance
public ObjectInstance(ObjectName objectName, String className)
From source file:org.ops4j.gaderian.management.TestMBeanRegistry.java
/** * Tests the registration of MBeans via contribution *//*from w w w . ja va2 s .co m*/ public void testContribution() throws Exception { Registry registry = buildFrameworkRegistry("testMBeanRegistry.xml", false); List mBeanList = registry.getConfiguration("gaderian.management.MBeans"); // Training ServicePoint sp1 = ((MBeanRegistrationContribution) mBeanList.get(0)).getServicePoint(); Object mBean1 = registry.getService("test.management.MBean1", Runnable.class); ObjectName on1 = objectNameBuilder.createServiceObjectName(sp1); ObjectInstance oin1 = new ObjectInstance(on1, mBean1.getClass().getName()); expect(server.registerMBean(mBean1, on1)).andReturn(oin1); Object mBean2 = registry.getService("test.management.MBean2", Runnable.class); ObjectName on2 = new ObjectName("gaderian:name=bean2"); expect(server.registerMBean(mBean2, on2)).andReturn(new ObjectInstance(on2, mBean2.getClass().getName())); // This is a special case. A class without interface Object mBean3 = registry.getService("test.management.MBean3", MBeanNonInterfaceTestService.class); ObjectName on3 = new ObjectName("gaderian:name=bean3"); expect(server.registerMBean(mBean3, on3)).andReturn(new ObjectInstance(on3, mBean3.getClass().getName())); // Call from unregisterBean expect(server.getObjectInstance(on1)).andReturn(oin1); server.unregisterMBean(on1); // The automatically unregistered beans get unregistered in reverse order server.unregisterMBean(on3); server.unregisterMBean(on2); replayAllRegisteredMocks(); MBeanRegistry mbeanRegistry = new MBeanRegistryImpl(errorHandler, log, server, objectNameBuilder, mBeanList); // Unregister one bean manually the other one during registry shutdown mbeanRegistry.unregisterMBean(on1); ((RegistryShutdownListener) mbeanRegistry).registryDidShutdown(); verifyAllRegisteredMocks(); assertTrue("start method has not been called", ((MBeanTestService) mBean1).isStartCalled()); registry.shutdown(); }
From source file:org.jolokia.detector.ServerHandleTest.java
@Test public void registerAtMBeanServer() throws MalformedObjectNameException, MBeanRegistrationException, InstanceAlreadyExistsException, NotCompliantMBeanException { Config config = new Config(null, null, null); ObjectName oName = new ObjectName("jolokia:type=Config"); ObjectInstance oInstance = new ObjectInstance(oName, Config.class.getName()); MBeanServer server = EasyMock.createMock(MBeanServer.class); expect(server.registerMBean(eq(config), eq(oName))).andReturn(oInstance); replay(server);//from w w w .j a va 2 s . co m ObjectName resName = serverHandle.registerMBeanAtServer(server, config, "jolokia:type=Config"); assertEquals(resName, oName); verify(server); }
From source file:org.jolokia.detector.ServerHandleTest.java
@Test public void registerAtMBeanServer2() throws MalformedObjectNameException, MBeanRegistrationException, InstanceAlreadyExistsException, NotCompliantMBeanException { Config config = new Config(null, null, null); ObjectInstance oInstance = new ObjectInstance("jolokia:type=dummy", Config.class.getName()); MBeanServer server = EasyMock.createMock(MBeanServer.class); expect(server.registerMBean(config, null)).andReturn(oInstance); replay(server);/*from w w w . j a v a 2 s .c o m*/ ObjectName resName = serverHandle.registerMBeanAtServer(server, config, null); assertEquals(resName, new ObjectName("jolokia:type=dummy")); verify(server); }
From source file:org.ops4j.gaderian.management.TestMBeanRegistry.java
/** * Ensures that a bean that doesn't implement one of the standard JMX * interfaces (like DynamicMBean) is registered as StandardMBean. */// w ww.jav a 2s. c om public void testStandardMBean() throws Exception { Calculator calculatorMBean = new CalculatorImpl(); ObjectName objectName = new ObjectName("gaderian:module=test"); // Training expect(server.registerMBean(calculatorMBean, objectName)) .andThrow(new NotCompliantMBeanException("Not compliant")); expect(server.registerMBean(isA(StandardMBean.class), eq(objectName))) .andReturn(new ObjectInstance(objectName, StandardMBean.class.getName())); replayAllRegisteredMocks(); MBeanRegistry mbeanRegistry = new MBeanRegistryImpl(errorHandler, log, server, objectNameBuilder, null); // Management interface is specified mbeanRegistry.registerMBean(calculatorMBean, Calculator.class, objectName); verifyAllRegisteredMocks(); }