1 25 package org.objectweb.petals.kernel.jmx; 26 27 import java.rmi.registry.LocateRegistry ; 28 import java.rmi.registry.Registry ; 29 30 import javax.management.remote.JMXConnectorServer ; 31 import javax.management.remote.JMXConnectorServerFactory ; 32 import javax.management.remote.JMXServiceURL ; 33 import javax.management.remote.rmi.RMIConnectorServer ; 34 35 import org.objectweb.fractal.fraclet.annotation.FractalComponent; 36 import org.objectweb.fractal.fraclet.annotation.LifeCycle; 37 import org.objectweb.fractal.fraclet.annotation.LifeCycleType; 38 import org.objectweb.fractal.fraclet.annotation.Monolog; 39 import org.objectweb.fractal.fraclet.annotation.Requires; 40 import org.objectweb.fractal.jmx.agent.AdminAttributes; 41 import org.objectweb.petals.util.LoggingUtil; 42 import org.objectweb.petals.util.SystemUtil; 43 import org.objectweb.util.monolog.api.Logger; 44 45 50 @FractalComponent 51 public class RMIConnector { 52 53 56 @Requires(name="adminAtt",signature=org.objectweb.fractal.jmx.agent.AdminAttributes.class) 57 protected AdminAttributes adminAttributes; 58 59 62 protected LoggingUtil log; 63 64 67 @Monolog(name="logger") 68 protected Logger logger; 69 70 73 protected JMXConnectorServer cs; 74 75 78 @LifeCycle(on=LifeCycleType.START) 79 public void start() { 80 log=new LoggingUtil(null); 81 log.start(); 82 try { 83 int port = Integer.parseInt(SystemUtil.getJmxPort()); 85 String host = SystemUtil.getHost(); 86 87 if (cs != null && cs.isActive() 88 && cs.getAddress().getPort() == port) { 89 return; 90 } 91 if (cs != null) { 92 cs.stop(); 93 } 94 Registry registry = LocateRegistry.getRegistry(port); 96 try { 97 registry.list(); 98 } catch (Exception e) { 99 LocateRegistry.createRegistry(port); 100 } 101 String sJmxURL = "service:jmx:rmi:///jndi/rmi://" + host + ":" 102 + port + "/management/rmi-jmx-connector"; 103 JMXServiceURL jmxUrl = new JMXServiceURL (sJmxURL); 104 114 RMIConnectorServer connectorServer = (RMIConnectorServer ) JMXConnectorServerFactory 116 .newJMXConnectorServer(jmxUrl, null, adminAttributes 117 .getRawMBeanServer()); 118 cs = connectorServer; 119 cs.start(); 121 log.info("JMX RMI server started at : " 123 + cs.getAddress().getURLPath()); 124 } catch (Exception e) { 125 log.error( 126 "Error during the instanciation of the MX4J RMI adaptor:", e); 127 } 128 log.end(); 129 } 130 131 134 @LifeCycle(on=LifeCycleType.STOP) 135 public void stop() { 136 log.start(); 137 if (cs != null) { 138 StopJMXServerThread stopJMXServerThread = new StopJMXServerThread( 139 cs, log); 140 stopJMXServerThread.start(); 141 } 142 log.end(); 143 } 144 145 } 146 | Popular Tags |