JmxRmi { static JmxConnector init(Properties props) throws IOException { Integer port = Integer.decode(props.getProperty(JMXEndpoint.JMX_RMI_PORT_PROPERTY)); if (!JmxConnectors.isPortAvailable(port)) return null; String name = "com.devexperts.qd.monitoring:type=RmiServer,port=" + port; RMIJRMPServerImpl srvImpl = new RMIJRMPServerImpl(port, null, null, null); RMIConnectorServer rmiServer = new RMIConnectorServer( new JMXServiceURL("service:jmx:rmi: null, srvImpl, ManagementFactory.getPlatformMBeanServer()); ConnectorImpl connector = new ConnectorImpl(port, name, rmiServer); if (!JmxConnectors.addConnector(connector)) return null; Registry registry = LocateRegistry.createRegistry(port); connector.setRegistry(registry); connector.setRegistration(Management.registerMBean(rmiServer, null, name)); rmiServer.start(); QDLog.log.info("RMI management port is " + port); return connector; } private  JmxRmi();   }
@Test public void testRmiRestart() throws IOException, InterruptedException { Properties props = new Properties(); int port = 11987; props.put("jmx.rmi.port", String.valueOf(port)); JmxConnector jmxConnector = JmxRmi.init(props); Assert.assertNotNull(jmxConnector); jmxConnector.stop(); waitForSocket(port); jmxConnector = JmxRmi.init(props); Assert.assertNotNull(jmxConnector); jmxConnector.stop(); }