public void startServer ( ) { if ( ! System . getProperties ( ) . containsKey ( JMX_ENABLED_PROPERTY ) ) { this . logger . info ( "System Property '" + JMX_ENABLED_PROPERTY + "' is not set, skipping initialization." ) ; return ; } try { // Get the base rmi port final int portOne = this . getPortOne ( ) ; // Get the second rmi port or calculate it final int portTwo = this . calculatePortTwo ( portOne ) ; // Create the RMI registry on the base port try { LocateRegistry . createRegistry ( portOne ) ; if ( this . logger . isDebugEnabled ( ) ) { this . logger . debug ( "Started RMI Registry on port " + portOne ) ; } } catch ( RemoteException re ) { throw new IllegalStateException ( "Could not create RMI Registry on port " + portOne , re ) ; } // Generate the JMX Service URL final JMXServiceURL jmxServiceUrl = this . getServiceUrl ( portOne , portTwo ) ; // Map for the JMX environment configuration final Map < String , Object > jmxEnv = this . getJmxServerEnvironment ( ) ; // Create the MBean Server final MBeanServer mbeanServer = ManagementFactory . getPlatformMBeanServer ( ) ; // Create the JMX Connector try { this . jmxConnectorServer = JMXConnectorServerFactory . newJMXConnectorServer ( jmxServiceUrl , jmxEnv , mbeanServer ) ; if ( this . logger . isDebugEnabled ( ) ) { this . logger . debug ( "Created JMXConnectorServer for JMXServiceURL='" + jmxServiceUrl + "', jmxEnv='" + jmxEnv + "' MBeanServer='" + mbeanServer + "'" ) ; } } catch ( IOException ioe ) { throw new IllegalStateException ( "Failed to create a new JMXConnectorServer for JMXServiceURL='" + jmxServiceUrl + "', jmxEnv='" + jmxEnv + "' MBeanServer='" + mbeanServer + "'" , ioe ) ; } // Start the JMX Connector try { this . jmxConnectorServer . start ( ) ; this . logger . info ( "Started JMXConnectorServer. Listening on '" + jmxServiceUrl + "'" ) ; } catch ( IOException ioe ) { throw new IllegalStateException ( "Failed to start the JMXConnectorServer" , ioe ) ; } } catch ( RuntimeException re ) { if ( this . failOnException ) { throw re ; } this . logger . error ( "Failed to initialize the JMX Server" , re ) ; } }
Starts the RMI server and JMX connector server