1 2 package SOFA.SOFAnode.Run.DeplDockRegistry; 3 4 import java.net.InetAddress ; 5 import java.net.UnknownHostException ; 6 import java.util.Hashtable ; 7 8 import org.omg.CORBA.ORB ; 9 import org.omg.CosNaming.NameComponent ; 10 import org.omg.CosNaming.NamingContext ; 11 import org.omg.CosNaming.NamingContextHelper ; 12 import org.omg.PortableServer.POA ; 13 import org.omg.PortableServer.POAHelper ; 14 15 19 class DeplDockRegistryServant implements DeplDockRegistryOperations { 20 21 Hashtable store; 22 long id; 23 String nodeName; 24 SOFA.Util.Lock lock; 25 26 public DeplDockRegistryServant (String nodeName) { 27 store = new Hashtable (); 28 id = 0; 29 this.nodeName = nodeName; 30 lock = new SOFA.Util.Lock(false); 31 } 32 33 public short register (byte[] sofaReference, String name) { 34 if (store.containsKey(name)) { 35 return 1; 36 } 37 store.put(new String (name), new Item(sofaReference)); 38 return 0; 39 } 40 41 public byte[] lookup (String name) throws SOFA.SOFAnode.Run.DeplDockRegistry.NotFoundException { 42 Item a = (Item) store.get(name); 43 if (a == null) 44 throw new NotFoundException(); 45 return a.obj; 46 } 47 48 public String [] getAllNames () { 49 String [] ret = new String [store.size()] ; 50 int i = 0; 51 for (java.util.Enumeration e = store.keys() ; e.hasMoreElements() ;) { 52 ret[i] = new String ((String ) e.nextElement()); 53 i++; 54 } 55 return ret; 56 } 57 58 public String getUniqueID() { 59 String ret; 60 lock.lock(); 61 ret = nodeName + Long.toString(id++); 62 lock.unlock(); 63 return ret; 64 } 65 } 66 67 class Item { 68 byte[] obj; 69 public Item(byte[] o) { obj = o; } 70 } 71 72 76 public class DeplDockRegistryServer { 77 public static void main(String [] argv) { 78 try{ 79 String sofaNodeName = System.getProperty("sofa.nodename",""); 80 81 if (sofaNodeName.compareTo("")==0) { 82 try { 83 sofaNodeName = InetAddress.getLocalHost().getHostName(); 84 } catch (UnknownHostException e) { 85 System.err.println("Can't get SOFAnode name. Set name manually."); 86 System.exit(1); 87 } 88 } 89 90 93 94 ORB orb = ORB.init(argv, null); 95 96 DeplDockRegistryServant servant = new DeplDockRegistryServant(sofaNodeName); 97 98 POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); 99 rootpoa.the_POAManager().activate(); 100 101 DeplDockRegistryPOATie tie = new DeplDockRegistryPOATie(servant, rootpoa); 102 DeplDockRegistry ref = tie._this(orb); 103 104 org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService"); 105 NamingContext ncRef = NamingContextHelper.narrow(objRef); 106 107 NameComponent nc = new NameComponent ("DeplDockRegistry", ""); 108 NameComponent path[] = { nc }; 109 ncRef.rebind(path, ref); 110 111 112 if (System.getSecurityManager() == null) { 113 System.setSecurityManager(new java.rmi.RMISecurityManager ()); 114 } 115 String rmiport = System.getProperty("sofa.rmiport","1099"); 116 String rmihost = System.getProperty("sofa.rmihost","localhost"); 117 java.rmi.Naming.rebind("//"+rmihost+":"+rmiport+"/RgRMIDock", new RgRMIDockImpl() ); 118 119 120 System.out.println("DeplDockRegistry is running."); 121 122 java.lang.Object sync = new java.lang.Object (); 123 synchronized (sync) { 124 sync.wait(); 125 } 126 127 } catch (Exception e) { 128 System.err.println("Exception: " + e); 129 e.printStackTrace(System.out); 130 } 131 } 132 } 133 | Popular Tags |