1 26 package org.objectweb.carol.jndi.ns; 27 28 import org.objectweb.carol.cmi.ClusterRegistry; 29 import org.objectweb.carol.cmi.ClusterRegistryImpl; 30 import org.objectweb.carol.cmi.ClusterRegistryKiller; 31 import org.objectweb.carol.cmi.DistributedEquiv; 32 import org.objectweb.carol.util.configuration.TraceCarol; 33 34 39 public class CmiRegistry extends AbsRegistry implements NameService { 40 41 44 private DistributedEquiv de = null; 45 46 49 private ClusterRegistryKiller cregk = null; 50 51 54 public CmiRegistry() { 55 super(ClusterRegistry.DEFAULT_PORT); 56 } 57 58 59 64 public void start() throws NameServiceException { 65 if (TraceCarol.isDebugJndiCarol()) { 66 TraceCarol.debugJndiCarol("CmiRegistry.start() on port:" + getPort()); 67 } 68 try { 69 if (!isStarted()) { 70 if (getPort() >= 0) { 71 de = DistributedEquiv.start(); 72 cregk = ClusterRegistryImpl.start(getPort()); 73 Runtime.getRuntime().addShutdownHook(new Thread () { 75 76 public void run() { 77 try { 78 CmiRegistry.this.stop(); 79 } catch (Exception e) { 80 TraceCarol.error("CmiRegistry ShutdownHook problem", e); 81 } 82 } 83 }); 84 } else { 85 if (TraceCarol.isDebugJndiCarol()) { 86 TraceCarol.debugJndiCarol("Can't start CmiRegistry, port=" + getPort() + " is < 0"); 87 } 88 } 89 } else { 90 if (TraceCarol.isDebugJndiCarol()) { 91 TraceCarol.debugJndiCarol("CmiRegistry is already start on port:" + getPort()); 92 } 93 } 94 } catch (Exception e) { 95 String msg = "can not start cluster registry: " + e; 96 TraceCarol.error(msg); 97 throw new NameServiceException(msg); 98 } 99 } 100 101 106 public void stop() throws NameServiceException { 107 if (TraceCarol.isDebugJndiCarol()) { 108 TraceCarol.debugJndiCarol("CmiRegistry.stop()"); 109 } 110 try { 111 if (cregk != null) { 112 cregk.stop(); 113 de.stop(); 114 cregk = null; 115 } 116 } catch (Exception e) { 117 throw new NameServiceException("can not stop cluster registry: " + e); 118 } 119 } 120 121 125 public boolean isStarted() { 126 if (cregk != null) { 127 return true; 128 } 129 return false; 130 } 131 132 } | Popular Tags |