1 7 8 package java.rmi.registry; 9 10 import java.rmi.RemoteException ; 11 import java.rmi.server.ObjID ; 12 import java.rmi.server.RMIClientSocketFactory ; 13 import java.rmi.server.RMIServerSocketFactory ; 14 import java.rmi.server.RemoteRef ; 15 import java.rmi.server.UnicastRemoteObject ; 16 import sun.rmi.registry.RegistryImpl; 17 import sun.rmi.server.UnicastRef2; 18 import sun.rmi.server.UnicastRef; 19 import sun.rmi.server.Util; 20 import sun.rmi.transport.LiveRef; 21 import sun.rmi.transport.tcp.TCPEndpoint; 22 23 40 public final class LocateRegistry { 41 42 45 private LocateRegistry() {} 46 47 55 public static Registry getRegistry() 56 throws RemoteException 57 { 58 return getRegistry(null, Registry.REGISTRY_PORT); 59 } 60 61 70 public static Registry getRegistry(int port) 71 throws RemoteException 72 { 73 return getRegistry(null, port); 74 } 75 76 86 public static Registry getRegistry(String host) 87 throws RemoteException 88 { 89 return getRegistry(host, Registry.REGISTRY_PORT); 90 } 91 92 103 public static Registry getRegistry(String host, int port) 104 throws RemoteException 105 { 106 return getRegistry(host, port, null); 107 } 108 109 127 public static Registry getRegistry(String host, int port, 128 RMIClientSocketFactory csf) 129 throws RemoteException 130 { 131 Registry registry = null; 132 133 if (port <= 0) 134 port = Registry.REGISTRY_PORT; 135 136 if (host == null || host.length() == 0) { 137 try { 141 host = java.net.InetAddress.getLocalHost().getHostAddress(); 142 } catch (Exception e) { 143 host = ""; 145 } 146 } 147 148 158 LiveRef liveRef = 159 new LiveRef(new ObjID (ObjID.REGISTRY_ID), 160 new TCPEndpoint(host, port, csf, null), 161 false); 162 RemoteRef ref = 163 (csf == null) ? new UnicastRef(liveRef) : new UnicastRef2(liveRef); 164 165 return (Registry ) Util.createProxy(RegistryImpl.class, ref, false); 166 } 167 168 185 public static Registry createRegistry(int port) throws RemoteException { 186 return new RegistryImpl(port); 187 } 188 189 217 public static Registry createRegistry(int port, 218 RMIClientSocketFactory csf, 219 RMIServerSocketFactory ssf) 220 throws RemoteException 221 { 222 return new RegistryImpl(port, csf, ssf); 223 } 224 } 225 | Popular Tags |