1 package twcsckernel.projectbase.rmi.registry; 2 3 import java.rmi.NotBoundException; 4 import java.rmi.Remote; 5 import java.rmi.RemoteException; 6 import java.rmi.server.ObjID; 7 import java.rmi.server.RMIClientSocketFactory; 8 import java.rmi.server.RMIServerSocketFactory; 9 10 import sun.rmi.server.UnicastServerRef; 11 import sun.rmi.server.UnicastServerRef2; 12 import sun.rmi.transport.LiveRef; 13 14 public class RegistryImpl extends java.rmi.server.RemoteServer implements 15 Registry { 16 17 private static final long serialVersionUID = 1L; 18 19 private static ObjID id = new ObjID(0); 20 21 private Remote remoteServer = null; 22 23 public RegistryImpl(int i) throws RemoteException { 24 LiveRef liveref = new LiveRef(id, i); 25 setup(new UnicastServerRef(liveref)); 26 } 27 28 public RegistryImpl(int i, RMIClientSocketFactory rmiclientsocketfactory, 29 RMIServerSocketFactory rmiserversocketfactory) 30 throws RemoteException { 31 LiveRef liveref = new LiveRef(id, i, rmiclientsocketfactory, 32 rmiserversocketfactory); 33 setup(new UnicastServerRef2(liveref)); 34 } 35 36 private void setup(UnicastServerRef unicastserverref) 37 throws RemoteException { 38 ref = unicastserverref; 39 unicastserverref.exportObject(this, null, true); 40 } 41 42 public static ObjID getID() { 43 return id; 44 } 45 46 public Remote getRemoteServer() throws RemoteException, NotBoundException { 47 if (remoteServer == null) 48 throw new NotBoundException(); 49 return remoteServer; 50 } 51 52 public void registerRemoteServer(Remote server) { 53 remoteServer = server; 54 } 55 56 }