1 28 package org.objectweb.carol.jndi.ns; 29 30 import java.rmi.RemoteException ; 31 import java.rmi.registry.Registry ; 32 33 import org.objectweb.jeremie.binding.moa.UnicastRemoteObject; 34 import org.objectweb.jeremie.services.registry.LocateRegistry; 35 36 import org.objectweb.carol.rmi.util.PortNumber; 37 import org.objectweb.carol.util.configuration.CarolDefaultValues; 38 import org.objectweb.carol.util.configuration.TraceCarol; 39 40 45 public class JeremieRegistry extends AbsRegistry implements NameService { 46 47 50 private static final int DEFAULT_PORT_NUMBER = 12340; 51 52 55 private Registry registry = null; 56 57 60 public JeremieRegistry() { 61 super(DEFAULT_PORT_NUMBER); 62 } 63 64 69 public void start() throws NameServiceException { 70 if (TraceCarol.isDebugJndiCarol()) { 71 TraceCarol.debugJndiCarol("JeremieRegistry.start() on port:" + getPort()); 72 } 73 74 if (System.getProperty(CarolDefaultValues.SERVER_MODE, "false").equalsIgnoreCase("true")) { 76 if (getConfigProperties() != null) { 77 String propertyName = CarolDefaultValues.SERVER_JEREMIE_PORT; 78 int jeremiePort = PortNumber.strToint(getConfigProperties().getProperty(propertyName, "0"), 79 propertyName); 80 if (jeremiePort > 0) { 81 TraceCarol.infoCarol("Using Jeremie fixed server port number '" + jeremiePort + "'."); 82 System.setProperty("org.objectweb.jeremie.stub_factories.defaultport", String.valueOf(jeremiePort)); 83 } 84 } else { 85 TraceCarol.debugCarol("No properties '" + CarolDefaultValues.SERVER_IIOP_PORT 86 + "' defined in carol.properties file."); 87 } 88 } 89 90 try { 91 if (!isStarted()) { 92 if (getPort() >= 0) { 93 registry = LocateRegistry.createRegistry(getPort()); 94 Runtime.getRuntime().addShutdownHook(new Thread () { 96 97 public void run() { 98 try { 99 JeremieRegistry.this.stop(); 100 } catch (Exception e) { 101 TraceCarol.error("JeremieRegistry ShutdownHook problem", e); 102 } 103 } 104 }); 105 } else { 106 if (TraceCarol.isDebugJndiCarol()) { 107 TraceCarol.debugJndiCarol("Can't start JeremieRegistry, port=" + getPort() + " is < 0"); 108 } 109 } 110 111 } else { 112 if (TraceCarol.isDebugJndiCarol()) { 113 TraceCarol.debugJndiCarol("JeremieRegistry is already start on port:" + getPort()); 114 } 115 } 116 } catch (Exception e) { 117 throw new NameServiceException("can not start jeremie registry: " + e); 118 } 119 } 120 121 126 public void stop() throws NameServiceException { 127 if (TraceCarol.isDebugJndiCarol()) { 128 TraceCarol.debugJndiCarol("JeremieRegistry.stop()"); 129 } 130 try { 131 if (registry != null) { 132 UnicastRemoteObject.unexportObject(registry, true); 133 } 134 registry = null; 135 } catch (Exception e) { 136 throw new NameServiceException("can not stop jeremie registry: " + e); 137 } 138 } 139 140 144 public boolean isStarted() { 145 if (registry != null) { 146 return true; 147 } 148 try { 149 LocateRegistry.getRegistry(getPort()).list(); 150 } catch (RemoteException re) { 151 return false; 152 } 153 return true; 154 } 155 } | Popular Tags |