public void destroy() throws Exception { if (rmiPort > 0) { connectorServer.stop(); } penroseService.destroy(); log.warn("JMX Service has been shutdown."); }
public void init() throws Exception { super.init(); ServiceConfig serviceConfig = getServiceConfig(); String s = serviceConfig.getParameter(RMI_PORT); rmiPort = s == null ? PenroseClient.DEFAULT_RMI_PORT : Integer.parseInt(s); s = serviceConfig.getParameter(RMI_TRANSPORT_PORT); rmiTransportPort = s == null ? PenroseClient.DEFAULT_RMI_TRANSPORT_PORT : Integer.parseInt(s); mbeanServer = ManagementFactory.getPlatformMBeanServer(); penroseService = new PenroseService(this, serviceContext.getPenroseServer()); penroseService.init(); if (rmiPort > 0) { LocateRegistry.createRegistry(rmiPort); String url = "service:jmx:rmi://localhost"; if (rmiTransportPort != PenroseClient.DEFAULT_RMI_TRANSPORT_PORT) url += ":" + rmiTransportPort; url += "/jndi/rmi://localhost"; if (rmiPort != PenroseClient.DEFAULT_RMI_PORT) url += ":" + rmiPort; url += "/penrose"; // String url = // "service:jmx:rmi://localhost:rmiTransportProtocol/jndi:rmi://localhost:rmiProtocol/penrose"; JMXServiceURL serviceURL = new JMXServiceURL(url); authenticator = new PenroseAuthenticator(serviceContext.getPenroseServer().getPenrose()); HashMap<String, Object> environment = new HashMap<String, Object>(); environment.put(JMXConnectorServer.AUTHENTICATOR, authenticator); connectorServer = new PenroseConnectorServer(serviceURL, environment, mbeanServer); connectorServer.start(); log.warn("Listening to port " + rmiPort + " (RMI)."); if (rmiTransportPort != PenroseClient.DEFAULT_RMI_TRANSPORT_PORT) log.warn("Listening to port " + rmiTransportPort + " (RMI Transport)."); } }