Java Code Examples for javax.management.MBeanServer#getObjectInstance()
The following examples show how to use
javax.management.MBeanServer#getObjectInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MBeanExporterTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testAutodetectMBeans() throws Exception { ConfigurableApplicationContext ctx = load("autodetectMBeans.xml"); try { ctx.getBean("exporter"); MBeanServer server = ctx.getBean("server", MBeanServer.class); ObjectInstance instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=true")); assertNotNull(instance); instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean2=true")); assertNotNull(instance); instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean3=true")); assertNotNull(instance); } finally { ctx.close(); } }
Example 2
Source File: MBeanExporterTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testAutodetectWithExclude() throws Exception { ConfigurableApplicationContext ctx = load("autodetectMBeans.xml"); try { ctx.getBean("exporter"); MBeanServer server = ctx.getBean("server", MBeanServer.class); ObjectInstance instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=true")); assertNotNull(instance); assertThatExceptionOfType(InstanceNotFoundException.class).isThrownBy(() -> server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=false"))); } finally { ctx.close(); } }
Example 3
Source File: MBeanExporterTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testAutodetectMBeans() throws Exception { ConfigurableApplicationContext ctx = load("autodetectMBeans.xml"); try { ctx.getBean("exporter"); MBeanServer server = ctx.getBean("server", MBeanServer.class); ObjectInstance instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=true")); assertNotNull(instance); instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean2=true")); assertNotNull(instance); instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean3=true")); assertNotNull(instance); } finally { ctx.close(); } }
Example 4
Source File: MBeanExporterTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testAutodetectWithExclude() throws Exception { ConfigurableApplicationContext ctx = load("autodetectMBeans.xml"); try { ctx.getBean("exporter"); MBeanServer server = ctx.getBean("server", MBeanServer.class); ObjectInstance instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=true")); assertNotNull(instance); thrown.expect(InstanceNotFoundException.class); server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=false")); } finally { ctx.close(); } }
Example 5
Source File: MBeanExporterTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testAutodetectMBeans() throws Exception { ConfigurableApplicationContext ctx = load("autodetectMBeans.xml"); try { ctx.getBean("exporter"); MBeanServer server = ctx.getBean("server", MBeanServer.class); ObjectInstance instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=true")); assertNotNull(instance); instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean2=true")); assertNotNull(instance); instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean3=true")); assertNotNull(instance); } finally { ctx.close(); } }
Example 6
Source File: MBeanExporterTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testAutodetectWithExclude() throws Exception { ConfigurableApplicationContext ctx = load("autodetectMBeans.xml"); try { ctx.getBean("exporter"); MBeanServer server = ctx.getBean("server", MBeanServer.class); ObjectInstance instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=true")); assertNotNull(instance); thrown.expect(InstanceNotFoundException.class); server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=false")); } finally { ctx.close(); } }
Example 7
Source File: ThroughputQueueSingleThreadTest.java From streams with Apache License 2.0 | 6 votes |
/** * Test that mulitple mbeans of the same type with a different name can be registered */ @Test public void testMultipleMBeanRegistrations() { try { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); Integer beanCount = mbs.getMBeanCount(); int numReg = randomIntBetween(2, 100); for(int i=0; i < numReg; ++i) { ThroughputQueue queue = new ThroughputQueue(MBEAN_ID + "" + i, STREAM_ID, STREAM_START_TIME); Assert.assertEquals("Expected bean to be registered", new Integer(beanCount + (i+1)), mbs.getMBeanCount()); ObjectInstance mBean = mbs.getObjectInstance(new ObjectName(String.format(ThroughputQueue.NAME_TEMPLATE, MBEAN_ID + "" + i, STREAM_ID, STREAM_START_TIME))); Assert.assertNotNull(mBean); } } catch (Exception e) { Assert.fail("Assert.failed to register MXBean : "+e.getMessage()); } }
Example 8
Source File: MCRJMXBridge.java From mycore with GNU General Public License v3.0 | 5 votes |
public static ObjectInstance getMBean(String type, String component) throws MalformedObjectNameException, InstanceNotFoundException { ObjectName name = getObjectName(type, component); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); if (mbs.isRegistered(name)) { return mbs.getObjectInstance(name); } return null; }
Example 9
Source File: ThroughputQueueSingleThreadTest.java From streams with Apache License 2.0 | 5 votes |
/** * Test that the mbean registers */ @Test public void testMBeanRegistration() { try { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); Integer beanCount = mbs.getMBeanCount(); ThroughputQueue queue = new ThroughputQueue(MBEAN_ID, STREAM_ID, STREAM_START_TIME); Assert.assertEquals("Expected bean to be registered", new Integer(beanCount+1), mbs.getMBeanCount()); ObjectInstance mBean = mbs.getObjectInstance(new ObjectName(String.format(ThroughputQueue.NAME_TEMPLATE, MBEAN_ID, STREAM_ID, STREAM_START_TIME))); Assert.assertNotNull(mBean); } catch (Exception e) { Assert.fail("Assert.failed to register MXBean : "+e.getMessage()); } }
Example 10
Source File: JMXArquillianTest.java From thorntail with Apache License 2.0 | 4 votes |
@Test public void testNothing() throws InterruptedException, MalformedObjectNameException, InstanceNotFoundException { MBeanServer server = locateMBeanServer(); ObjectInstance result = server.getObjectInstance(ObjectName.getInstance("jboss.msc:type=container,name=jboss-as")); assertNotNull(result); }
Example 11
Source File: PinpointMBeanServerTest.java From pinpoint with Apache License 2.0 | 4 votes |
@Test public void test() throws Exception { PinpointMBeanServer mBeanServer = new PinpointMBeanServer(); ATest aTest = new ATest(); mBeanServer.registerMBean(aTest); MBeanServer server = ManagementFactory.getPlatformMBeanServer(); String mBeanObjectName = "com.navercorp.pinpoint.collector.mbean:type=PinpointMBeanServerTest$ATest"; ObjectName objectName = new ObjectName(mBeanObjectName); String packageName = this.getClass().getPackage().getName(); ObjectInstance instance = server.getObjectInstance(objectName); Assert.assertEquals(packageName + ".PinpointMBeanServerTest$ATest", instance.getClassName()); mBeanServer.unregisterMBean(aTest); }