1 17 package org.apache.geronimo.system.rmi; 18 19 import java.rmi.registry.LocateRegistry ; 20 import java.rmi.registry.Registry ; 21 import java.rmi.server.UnicastRemoteObject ; 22 import java.net.InetSocketAddress ; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 import org.apache.geronimo.gbean.GBeanInfo; 27 import org.apache.geronimo.gbean.GBeanInfoBuilder; 28 import org.apache.geronimo.gbean.GBeanLifecycle; 29 30 35 public class RMIRegistryService implements GBeanLifecycle { 36 private static final Log log = LogFactory.getLog(RMIRegistryService.class); 37 private int port = Registry.REGISTRY_PORT; 38 private Registry registry; 39 40 public int getPort() { 41 return port; 42 } 43 44 public void setPort(int port) { 45 this.port = port; 46 } 47 48 public String getHost() { 49 return "0.0.0.0"; 50 } 51 52 public String getProtocol() { 53 return "rmi"; 54 } 55 56 public void doStart() throws Exception { 57 System.setProperty("java.rmi.server.RMIClassLoaderSpi",RMIClassLoaderSpiImpl.class.getName()); 58 registry = LocateRegistry.createRegistry(port); 59 log.debug("Started RMI Registry on port " + port); 60 } 61 62 public void doStop() throws Exception { 63 UnicastRemoteObject.unexportObject(registry, true); 64 log.debug("Stopped RMI Registry"); 65 } 66 67 public void doFail() { 68 try { 69 doStop(); 70 } catch (Exception e) { 71 log.warn("RMI Registry failed"); 72 } 73 } 74 75 public InetSocketAddress getListenAddress() { 76 return new InetSocketAddress (getHost(), getPort()); 77 } 78 79 public static final GBeanInfo GBEAN_INFO; 80 81 static { 82 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("RMI Naming", RMIRegistryService.class); 83 infoFactory.addAttribute("host", String .class, false); 84 infoFactory.addAttribute("protocol", String .class, false); 85 infoFactory.addAttribute("port", int.class, true, true); 86 infoFactory.addAttribute("listenAddress", InetSocketAddress .class, false); 87 GBEAN_INFO = infoFactory.getBeanInfo(); 88 } 89 90 public static GBeanInfo getGBeanInfo() { 91 return GBEAN_INFO; 92 } 93 } 94 | Popular Tags |