1 22 package org.objectweb.petals.kernel.admin.util; 23 24 import java.io.IOException ; 25 import java.rmi.registry.LocateRegistry ; 26 import java.rmi.registry.Registry ; 27 28 import javax.management.MBeanServer ; 29 import javax.management.MBeanServerFactory ; 30 import javax.management.ObjectName ; 31 import javax.management.remote.JMXConnectorServer ; 32 import javax.management.remote.JMXConnectorServerFactory ; 33 import javax.management.remote.JMXServiceURL ; 34 import javax.management.remote.rmi.RMIConnectorServer ; 35 36 41 public class ServerUtil { 42 43 46 public static boolean isStarted = false; 47 48 51 private static JMXConnectorServer cs; 52 53 59 public static int start(int port) throws Exception { 60 if (isStarted == false) { 61 Registry registry = LocateRegistry.getRegistry(port); 62 try { 63 registry.list(); 64 } 65 catch (Exception e){ 66 LocateRegistry.createRegistry(port); 67 } 68 MBeanServer beanServer = MBeanServerFactory.newMBeanServer(); 69 beanServer.registerMBean(new AdminServiceMoc(beanServer), new ObjectName ("FC/Petals/jbi/admin-impl@00001:itf=service")); 70 String sJmxURL = "service:jmx:rmi:///jndi/rmi://127.0.0.1:" + port + "/management/rmi-jmx-connector"; 71 JMXServiceURL jmxUrl = new JMXServiceURL (sJmxURL); 72 RMIConnectorServer connectorServer = (RMIConnectorServer ) JMXConnectorServerFactory.newJMXConnectorServer(jmxUrl, null, beanServer); 73 cs = connectorServer; 74 cs.start(); 75 isStarted = true; 77 } 78 return port; 79 } 80 81 87 public static void stop() throws IOException { 88 if (isStarted) { 89 isStarted = false; 90 cs.stop(); 91 } 92 } 93 } 94 | Popular Tags |