1 7 package java.rmi.server; 8 9 import java.rmi.*; 10 import sun.rmi.server.UnicastServerRef; 11 import sun.rmi.server.UnicastServerRef2; 12 13 90 public class UnicastRemoteObject extends RemoteServer { 91 92 95 private int port = 0; 96 97 100 private RMIClientSocketFactory csf = null; 101 102 106 private RMIServerSocketFactory ssf = null; 107 108 109 private static final long serialVersionUID = 4974527148936298033L; 110 111 117 protected UnicastRemoteObject() throws RemoteException 118 { 119 this(0); 120 } 121 122 130 protected UnicastRemoteObject(int port) throws RemoteException 131 { 132 this.port = port; 133 exportObject((Remote) this, port); 134 } 135 136 147 protected UnicastRemoteObject(int port, 148 RMIClientSocketFactory csf, 149 RMIServerSocketFactory ssf) 150 throws RemoteException 151 { 152 this.port = port; 153 this.csf = csf; 154 this.ssf = ssf; 155 exportObject((Remote) this, port, csf, ssf); 156 } 157 158 161 private void readObject(java.io.ObjectInputStream in) 162 throws java.io.IOException , java.lang.ClassNotFoundException 163 { 164 in.defaultReadObject(); 165 reexport(); 166 } 167 168 177 public Object clone() throws CloneNotSupportedException 178 { 179 try { 180 UnicastRemoteObject cloned = (UnicastRemoteObject ) super.clone(); 181 cloned.reexport(); 182 return cloned; 183 } catch (RemoteException e) { 184 throw new ServerCloneException ("Clone failed", e); 185 } 186 } 187 188 193 private void reexport() throws RemoteException 194 { 195 if (csf == null && ssf == null) { 196 exportObject((Remote) this, port); 197 } else { 198 exportObject((Remote) this, port, csf, ssf); 199 } 200 } 201 202 210 public static RemoteStub exportObject(Remote obj) 211 throws RemoteException 212 { 213 220 return (RemoteStub ) exportObject(obj, new UnicastServerRef(true)); 221 } 222 223 232 public static Remote exportObject(Remote obj, int port) 233 throws RemoteException 234 { 235 return exportObject(obj, new UnicastServerRef(port)); 236 } 237 238 250 public static Remote exportObject(Remote obj, int port, 251 RMIClientSocketFactory csf, 252 RMIServerSocketFactory ssf) 253 throws RemoteException 254 { 255 256 return exportObject(obj, new UnicastServerRef2(port, csf, ssf)); 257 } 258 259 277 public static boolean unexportObject(Remote obj, boolean force) 278 throws java.rmi.NoSuchObjectException 279 { 280 return sun.rmi.transport.ObjectTable.unexportObject(obj, force); 281 } 282 283 286 private static Remote exportObject(Remote obj, UnicastServerRef sref) 287 throws RemoteException 288 { 289 if (obj instanceof UnicastRemoteObject ) { 291 ((UnicastRemoteObject ) obj).ref = sref; 292 } 293 return sref.exportObject(obj, null, false); 294 } 295 } 296 | Popular Tags |