List of usage examples for javax.management.remote JMXConnectorServer toJMXConnector
public JMXConnector toJMXConnector(Map<String, ?> env) throws IOException
Returns a client stub for this connector server.
From source file:net.sf.ehcache.management.ManagementServiceTest.java
/** * Creates an RMI JMXConnectorServer, connects to it and demonstrates what attributes are traversable. * The answer is not all.//w ww. j a v a 2 s. com * * Note that this test creates a Registry which will keep running until the JVM Exists. There * is no way to stop it but it should do no harm. * * */ public void testJMXConnectorServer() throws Exception { ManagementService.registerMBeans(manager, mBeanServer, true, true, true, true); LocateRegistry.createRegistry(55000); String serverUrl = "service:jmx:rmi:///jndi/rmi://localhost:55000/server"; JMXServiceURL url = new JMXServiceURL(serverUrl); JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mBeanServer); cs.start(); JMXConnector connector = cs.toJMXConnector(null); connector.connect(null); MBeanServerConnection connection = connector.getMBeanServerConnection(); assertEquals(OBJECTS_IN_TEST_EHCACHE, connection.queryNames(new ObjectName("net.sf.ehcache:*"), null).size()); Ehcache ehcache = manager.getCache("sampleCache1"); ehcache.put(new Element("key1", "value1")); ehcache.put(new Element("key2", "value1")); assertNotNull(ehcache.get("key1")); assertNotNull(ehcache.get("key2")); //Test CacheManager //not all attributes are accessible due to serializability constraints //traverseMBeanAttributes(connection, "CacheManager"); //Test Cache //not all attributes are accessible due to serializability constraints //traverseMBeanAttributes(connection, "Cache"); //Test CacheStatistics traverseMBeanAttributes(connection, "CacheStatistics"); //Test CacheConfiguration traverseMBeanAttributes(connection, "CacheConfiguration"); cs.stop(); }