Java Code Examples for javax.management.MBeanServerFactory
The following examples show how to use
javax.management.MBeanServerFactory.
These examples are extracted from open source projects.
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 Project: java-technology-stack Author: codeEngraver File: MBeanServerFactoryBeanTests.java License: MIT License | 6 votes |
@Test public void withLocateExistingAndExistingServer() { MBeanServer server = MBeanServerFactory.createMBeanServer(); try { MBeanServerFactoryBean bean = new MBeanServerFactoryBean(); bean.setLocateExistingServerIfPossible(true); bean.afterPropertiesSet(); try { MBeanServer otherServer = bean.getObject(); assertSame("Existing MBeanServer not located", server, otherServer); } finally { bean.destroy(); } } finally { MBeanServerFactory.releaseMBeanServer(server); } }
Example #2
Source Project: jdk8u-jdk Author: lambdalab-mirror File: MBeanTest.java License: GNU General Public License v2.0 | 6 votes |
private static void testCompliant(Class<?> iface, Object bean) throws Exception { try { System.out.println("Registering a compliant MBean " + iface.getName() + " ..."); MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName on = new ObjectName("test:type=Compliant"); mbs.registerMBean(bean, on); success("Registered a compliant MBean - " + iface.getName()); } catch (Exception e) { Throwable t = e; while (t != null && !(t instanceof NotCompliantMBeanException)) { t = t.getCause(); } if (t != null) { fail("MBean not registered"); } else { throw e; } } }
Example #3
Source Project: jdk8u-jdk Author: frohoff File: ImmutableNotificationInfoTest.java License: GNU General Public License v2.0 | 6 votes |
private static boolean test(Object mbean, boolean expectImmutable) throws Exception { MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName on = new ObjectName("a:b=c"); mbs.registerMBean(mbean, on); MBeanInfo mbi = mbs.getMBeanInfo(on); Descriptor d = mbi.getDescriptor(); String immutableValue = (String) d.getFieldValue("immutableInfo"); boolean immutable = ("true".equals(immutableValue)); if (immutable != expectImmutable) { System.out.println("FAILED: " + mbean.getClass().getName() + " -> " + immutableValue); return false; } else { System.out.println("OK: " + mbean.getClass().getName()); return true; } }
Example #4
Source Project: hottub Author: dsrg-uoft File: MLetCommand.java License: GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { if (System.getSecurityManager() == null) throw new IllegalStateException("No security manager installed!"); System.out.println("java.security.policy=" + System.getProperty("java.security.policy")); // Instantiate the MBean server // System.out.println("Create the MBean server"); MBeanServer mbs = MBeanServerFactory.createMBeanServer(); // Register the MLetMBean // System.out.println("Create MLet MBean"); ObjectName mlet = new ObjectName("MLetTest:name=MLetMBean"); mbs.createMBean("javax.management.loading.MLet", mlet); // Test OK! // System.out.println("Bye! Bye!"); }
Example #5
Source Project: openjdk-jdk9 Author: AdoptOpenJDK File: MBeanTest.java License: GNU General Public License v2.0 | 6 votes |
private static void testCompliant(Class<?> iface, Object bean) throws Exception { try { System.out.println("Registering a compliant MBean " + iface.getName() + " ..."); MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName on = new ObjectName("test:type=Compliant"); mbs.registerMBean(bean, on); success("Registered a compliant MBean - " + iface.getName()); } catch (Exception e) { Throwable t = e; while (t != null && !(t instanceof NotCompliantMBeanException)) { t = t.getCause(); } if (t != null) { fail("MBean not registered"); } else { throw e; } } }
Example #6
Source Project: jdk8u-jdk Author: lambdalab-mirror File: ImmutableNotificationInfoTest.java License: GNU General Public License v2.0 | 6 votes |
private static boolean test(Object mbean, boolean expectImmutable) throws Exception { MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName on = new ObjectName("a:b=c"); mbs.registerMBean(mbean, on); MBeanInfo mbi = mbs.getMBeanInfo(on); Descriptor d = mbi.getDescriptor(); String immutableValue = (String) d.getFieldValue("immutableInfo"); boolean immutable = ("true".equals(immutableValue)); if (immutable != expectImmutable) { System.out.println("FAILED: " + mbean.getClass().getName() + " -> " + immutableValue); return false; } else { System.out.println("OK: " + mbean.getClass().getName()); return true; } }
Example #7
Source Project: openjdk-8-source Author: keerath File: ListenerScaleTest.java License: GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { MBeanServer mbs = MBeanServerFactory.newMBeanServer(); Sender sender = new Sender(); mbs.registerMBean(sender, testObjectName); JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://"); JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); cs.start(); JMXServiceURL addr = cs.getAddress(); JMXConnector cc = JMXConnectorFactory.connect(addr); try { test(mbs, cs, cc); } finally { cc.close(); cs.stop(); } }
Example #8
Source Project: jdk8u-jdk Author: lambdalab-mirror File: MLetCommand.java License: GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { if (System.getSecurityManager() == null) throw new IllegalStateException("No security manager installed!"); System.out.println("java.security.policy=" + System.getProperty("java.security.policy")); // Instantiate the MBean server // System.out.println("Create the MBean server"); MBeanServer mbs = MBeanServerFactory.createMBeanServer(); // Register the MLetMBean // System.out.println("Create MLet MBean"); ObjectName mlet = new ObjectName("MLetTest:name=MLetMBean"); mbs.createMBean("javax.management.loading.MLet", mlet); // Test OK! // System.out.println("Bye! Bye!"); }
Example #9
Source Project: TencentKona-8 Author: Tencent File: ListenerScaleTest.java License: GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { MBeanServer mbs = MBeanServerFactory.newMBeanServer(); Sender sender = new Sender(); mbs.registerMBean(sender, testObjectName); JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://"); JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); cs.start(); JMXServiceURL addr = cs.getAddress(); JMXConnector cc = JMXConnectorFactory.connect(addr); try { test(mbs, cs, cc); } finally { cc.close(); cs.stop(); } }
Example #10
Source Project: openjdk-8-source Author: keerath File: RuntimeExceptionTest.java License: GNU General Public License v2.0 | 6 votes |
/** * Test the monitor notifications. */ public int monitorNotifications() throws Exception { server = MBeanServerFactory.newMBeanServer(); MBeanServerForwarderInvocationHandler mbsfih = (MBeanServerForwarderInvocationHandler) Proxy.getInvocationHandler(server); mbsfih.setGetAttributeException( new RuntimeException("Test RuntimeException")); domain = server.getDefaultDomain(); obsObjName = ObjectName.getInstance(domain + ":type=ObservedObject"); server.registerMBean(new ObservedObject(), obsObjName); echo(">>> ----------------------------------------"); int error = counterMonitorNotification(); echo(">>> ----------------------------------------"); error += gaugeMonitorNotification(); echo(">>> ----------------------------------------"); error += stringMonitorNotification(); echo(">>> ----------------------------------------"); return error; }
Example #11
Source Project: gemfirexd-oss Author: gemxd File: ReplicatedTree.java License: Apache License 2.0 | 6 votes |
public ReplicatedTree(String groupname, String props, long state_fetch_timeout, boolean jmx) throws Exception { if(groupname != null) this.groupname=groupname; if(props != null) this.props=props; // this.jmx=jmx; GemStoneAddition this.state_fetch_timeout=state_fetch_timeout; channel=new JChannel(this.props); channel.connect(this.groupname); if(jmx) { ArrayList servers=MBeanServerFactory.findMBeanServer(null); if(servers == null || servers.size() == 0) { throw new Exception("No MBeanServers found;" + "\nJmxTest needs to be run with an MBeanServer present, or inside JDK 5"); } // MBeanServer server=(MBeanServer)servers.get(0); GemStoneAddition // JmxConfigurator.registerChannel(channel, server, "JGroups:channel=" + channel.getChannelName() , true); } start(); }
Example #12
Source Project: openjdk-8 Author: bpupadhyaya File: ExceptionDiagnosisTest.java License: GNU General Public License v2.0 | 6 votes |
private static void testCaseProb() throws Exception { MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName name = new ObjectName("a:b=c"); mbs.registerMBean(new CaseProbImpl(), name); CaseProbMXBean proxy = JMX.newMXBeanProxy(mbs, name, CaseProbMXBean.class); try { CaseProb prob = proxy.getCaseProb(); fail("No exception from proxy method getCaseProb"); } catch (IllegalArgumentException e) { String messageChain = messageChain(e); if (messageChain.contains("URLPath")) { System.out.println("Message chain contains URLPath as required: " + messageChain); } else { fail("Exception chain for CaseProb does not mention property" + " URLPath differing only in case"); System.out.println("Full stack trace:"); e.printStackTrace(System.out); } } }
Example #13
Source Project: jdk8u-dev-jdk Author: frohoff File: MBeanFallbackTest.java License: GNU General Public License v2.0 | 6 votes |
private static void testPrivate(Class<?> iface, Object bean) throws Exception { try { System.out.println("Registering a private MBean " + iface.getName() + " ..."); MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName on = new ObjectName("test:type=Compliant"); mbs.registerMBean(bean, on); success("Registered a private MBean - " + iface.getName()); } catch (Exception e) { Throwable t = e; while (t != null && !(t instanceof NotCompliantMBeanException)) { t = t.getCause(); } if (t != null) { fail("MBean not registered"); } else { throw e; } } }
Example #14
Source Project: jdk8u_jdk Author: JetBrains File: MBeanTest.java License: GNU General Public License v2.0 | 6 votes |
private static void testNonCompliant(Class<?> iface, Object bean) throws Exception { try { System.out.println("Registering a non-compliant MBean " + iface.getName() + " ..."); MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName on = new ObjectName("test:type=NonCompliant"); mbs.registerMBean(bean, on); fail("Registered a non-compliant MBean - " + iface.getName()); } catch (Exception e) { Throwable t = e; while (t != null && !(t instanceof NotCompliantMBeanException)) { t = t.getCause(); } if (t != null) { success("MBean not registered"); } else { throw e; } } }
Example #15
Source Project: openjdk-8 Author: bpupadhyaya File: JMXProxyFallbackTest.java License: GNU General Public License v2.0 | 6 votes |
private static void testPrivate(Class<?> iface) throws Exception { try { System.out.println("Creating a proxy for private M(X)Bean " + iface.getName() + " ..."); MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName on = new ObjectName("test:type=Proxy"); JMX.newMBeanProxy(mbs, on, iface); success("Created a proxy for private M(X)Bean - " + iface.getName()); } catch (Exception e) { Throwable t = e; while (t != null && !(t instanceof NotCompliantMBeanException)) { t = t.getCause(); } if (t != null) { fail("Proxy not created"); } else { throw e; } } }
Example #16
Source Project: openjdk-8 Author: bpupadhyaya File: ImmutableNotificationInfoTest.java License: GNU General Public License v2.0 | 6 votes |
private static boolean test(Object mbean, boolean expectImmutable) throws Exception { MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName on = new ObjectName("a:b=c"); mbs.registerMBean(mbean, on); MBeanInfo mbi = mbs.getMBeanInfo(on); Descriptor d = mbi.getDescriptor(); String immutableValue = (String) d.getFieldValue("immutableInfo"); boolean immutable = ("true".equals(immutableValue)); if (immutable != expectImmutable) { System.out.println("FAILED: " + mbean.getClass().getName() + " -> " + immutableValue); return false; } else { System.out.println("OK: " + mbean.getClass().getName()); return true; } }
Example #17
Source Project: activemq-artemis Author: apache File: JMSTestBase.java License: Apache License 2.0 | 6 votes |
@Override @Before public void setUp() throws Exception { super.setUp(); mbeanServer = MBeanServerFactory.createMBeanServer(); Configuration config = createDefaultConfig(true).setSecurityEnabled(useSecurity()). addConnectorConfiguration("invm", new TransportConfiguration(INVM_CONNECTOR_FACTORY)). setTransactionTimeoutScanPeriod(100); config.getConnectorConfigurations().put("netty", new TransportConfiguration(NETTY_CONNECTOR_FACTORY)); server = addServer(ActiveMQServers.newActiveMQServer(config, mbeanServer, usePersistence())); jmsServer = new JMSServerManagerImpl(server); namingContext = new InVMNamingContext(); jmsServer.setRegistry(new JndiBindingRegistry(namingContext)); jmsServer.start(); registerConnectionFactory(); }
Example #18
Source Project: jdk8u60 Author: chenghanpeng File: MBeanFallbackTest.java License: GNU General Public License v2.0 | 6 votes |
private static void testPrivate(Class<?> iface, Object bean) throws Exception { try { System.out.println("Registering a private MBean " + iface.getName() + " ..."); MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName on = new ObjectName("test:type=Compliant"); mbs.registerMBean(bean, on); success("Registered a private MBean - " + iface.getName()); } catch (Exception e) { Throwable t = e; while (t != null && !(t instanceof NotCompliantMBeanException)) { t = t.getCause(); } if (t != null) { fail("MBean not registered"); } else { throw e; } } }
Example #19
Source Project: jdk8u-jdk Author: lambdalab-mirror File: ExceptionDiagnosisTest.java License: GNU General Public License v2.0 | 6 votes |
private static void testCaseProb() throws Exception { MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName name = new ObjectName("a:b=c"); mbs.registerMBean(new CaseProbImpl(), name); CaseProbMXBean proxy = JMX.newMXBeanProxy(mbs, name, CaseProbMXBean.class); try { CaseProb prob = proxy.getCaseProb(); fail("No exception from proxy method getCaseProb"); } catch (IllegalArgumentException e) { String messageChain = messageChain(e); if (messageChain.contains("URLPath")) { System.out.println("Message chain contains URLPath as required: " + messageChain); } else { fail("Exception chain for CaseProb does not mention property" + " URLPath differing only in case"); System.out.println("Full stack trace:"); e.printStackTrace(System.out); } } }
Example #20
Source Project: openjdk-jdk8u Author: AdoptOpenJDK File: ListenerScaleTest.java License: GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { MBeanServer mbs = MBeanServerFactory.newMBeanServer(); Sender sender = new Sender(); mbs.registerMBean(sender, testObjectName); JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://"); JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); cs.start(); JMXServiceURL addr = cs.getAddress(); JMXConnector cc = JMXConnectorFactory.connect(addr); try { test(mbs, cs, cc); } finally { cc.close(); cs.stop(); } }
Example #21
Source Project: hottub Author: dsrg-uoft File: MBeanFallbackTest.java License: GNU General Public License v2.0 | 6 votes |
private static void testPrivate(Class<?> iface, Object bean) throws Exception { try { System.out.println("Registering a private MBean " + iface.getName() + " ..."); MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName on = new ObjectName("test:type=Compliant"); mbs.registerMBean(bean, on); success("Registered a private MBean - " + iface.getName()); } catch (Exception e) { Throwable t = e; while (t != null && !(t instanceof NotCompliantMBeanException)) { t = t.getCause(); } if (t != null) { fail("MBean not registered"); } else { throw e; } } }
Example #22
Source Project: groovy Author: apache File: MBeanTest.java License: Apache License 2.0 | 6 votes |
public void testGetProperty() throws Exception { MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer(); ObjectName name = new ObjectName("groovy.test:role=TestMBean,type=Dummy"); // use Class.forName instead of new Dummy() to allow separate compilation mbeanServer.registerMBean(Class.forName("groovy.jmx.Dummy").getDeclaredConstructor().newInstance(), name); assertEquals("JMX value of Name", "James", mbeanServer.getAttribute(name, "Name")); GroovyMBean object = new GroovyMBean(mbeanServer, name); Object value = object.getProperty("Name"); assertEquals("Name property", "James", value); object.setProperty("Name", "Bob"); assertEquals("Name property", "Bob", object.getProperty("Name")); // now let's look up the name via JMX to check assertEquals("JMX value of Name", "Bob", mbeanServer.getAttribute(name, "Name")); assertEquals("Location : London|Name : Bob|Size : 12", join(sort(object.listAttributeValues()), "|")); assertEquals("start|stop", join(sort(object.listOperationNames()), "|")); assertEquals("void start()", join(sort(object.describeOperation("start")), "|")); assertEquals("(rw) java.lang.String Location", object.describeAttribute("Location")); }
Example #23
Source Project: TencentKona-8 Author: Tencent File: ReflectionExceptionTest.java License: GNU General Public License v2.0 | 5 votes |
/** * Test the monitor notifications. */ public int monitorNotifications() throws Exception { server = MBeanServerFactory.newMBeanServer(); MBeanServerForwarderInvocationHandler mbsfih = (MBeanServerForwarderInvocationHandler) Proxy.getInvocationHandler(server); mbsfih.setGetAttributeException( new ReflectionException(new RuntimeException(), "Test ReflectionException")); domain = server.getDefaultDomain(); obsObjName = ObjectName.getInstance(domain + ":type=ObservedObject"); server.registerMBean(new ObservedObject(), obsObjName); echo(">>> ----------------------------------------"); int error = counterMonitorNotification(); echo(">>> ----------------------------------------"); error += gaugeMonitorNotification(); echo(">>> ----------------------------------------"); error += stringMonitorNotification(); echo(">>> ----------------------------------------"); return error; }
Example #24
Source Project: jdk8u-jdk Author: lambdalab-mirror File: ExceptionDiagnosisTest.java License: GNU General Public License v2.0 | 5 votes |
private static void testMXBeans(Object mbean, Type... expectedTypes) throws Exception { try { MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName name = new ObjectName("a:b=c"); mbs.registerMBean(mbean, name); fail("No exception from registerMBean for " + mbean); } catch (NotCompliantMBeanException e) { checkExceptionChain("MBean " + mbean, e, expectedTypes); } }
Example #25
Source Project: jdk8u-jdk Author: frohoff File: UnregisterMBeanExceptionTest.java License: GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { // Instantiate the MBean server // System.out.println("Create the MBean server"); MBeanServer mbs = MBeanServerFactory.createMBeanServer(); // Register the MBean // System.out.println("Create a TestDynamicMBean"); TestDynamicMBean obj = new TestDynamicMBean(); ObjectName n = new ObjectName("d:k=v"); System.out.println("Register a TestDynamicMBean"); mbs.registerMBean(obj, n); obj.throwException = true; System.out.println("Unregister a TestDynamicMBean"); try { mbs.unregisterMBean(n); } catch (Exception e) { throw new IllegalArgumentException("Test failed", e); } boolean isRegistered = mbs.isRegistered(n); System.out.println("Is MBean Registered? " + isRegistered); if (isRegistered) { throw new IllegalArgumentException( "Test failed: the MBean is still registered"); } else { System.out.println("Test passed"); } }
Example #26
Source Project: openjdk-8 Author: bpupadhyaya File: MXBeanTest.java License: GNU General Public License v2.0 | 5 votes |
private static void testNonCompliantMXBean(String type, Object bean) throws Exception { System.out.println(type + " MXBean test..."); MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName on = new ObjectName("test:type=" + type); try { mbs.registerMBean(bean, on); failure(bean.getClass().getInterfaces()[0].getName() + " is not a compliant " + "MXBean interface"); } catch (NotCompliantMBeanException e) { success("Non-compliant MXBean not registered"); } }
Example #27
Source Project: openjdk-jdk9 Author: AdoptOpenJDK File: ComparatorExceptionTest.java License: GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName name = new ObjectName("a:b=c"); mbs.registerMBean(new TestImpl(), name); for (String attr : new String[] {"SortedSet", "SortedMap"}) { try { Object value = mbs.getAttribute(name, attr); fail("get " + attr + " did not throw exception"); } catch (Exception e) { Throwable t = e; while (!(t instanceof IllegalArgumentException)) { if (t == null) break; t = t.getCause(); } if (t != null) System.out.println("Correct exception for " + attr); else { fail("get " + attr + " got wrong exception"); e.printStackTrace(System.out); } } } if (failure != null) throw new Exception(failure); }
Example #28
Source Project: jdk8u-dev-jdk Author: frohoff File: ExceptionDiagnosisTest.java License: GNU General Public License v2.0 | 5 votes |
private static void testMXBeans(Object mbean, Type... expectedTypes) throws Exception { try { MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName name = new ObjectName("a:b=c"); mbs.registerMBean(mbean, name); fail("No exception from registerMBean for " + mbean); } catch (NotCompliantMBeanException e) { checkExceptionChain("MBean " + mbean, e, expectedTypes); } }
Example #29
Source Project: hottub Author: dsrg-uoft File: MXBeanTest.java License: GNU General Public License v2.0 | 5 votes |
private static void testSubclassMXBean() throws Exception { System.out.println("Subclass MXBean test..."); MBeanServer mbs = MBeanServerFactory.newMBeanServer(); ObjectName on = new ObjectName("test:type=Subclass"); Subclass subclass = new Subclass(); mbs.registerMBean(subclass, on); testMXBean(mbs, on); }
Example #30
Source Project: activemq-artemis Author: apache File: OpenWireTestBase.java License: Apache License 2.0 | 5 votes |
@Override @After public void tearDown() throws Exception { MBeanServerFactory.releaseMBeanServer(mbeanServer); mbeanServer = null; server.stop(); super.tearDown(); }