1 7 8 package java.rmi.activation; 9 10 import java.lang.reflect.Constructor ; 11 12 import java.rmi.activation.UnknownGroupException ; 13 import java.rmi.activation.UnknownObjectException ; 14 import java.rmi.Remote ; 15 import java.rmi.RemoteException ; 16 import java.rmi.MarshalledObject ; 17 import java.rmi.NoSuchObjectException ; 18 19 import java.rmi.server.*; 20 21 import sun.rmi.server.ActivatableServerRef; 22 23 36 public abstract class Activatable extends RemoteServer { 37 38 41 private ActivationID id; 42 43 private static final long serialVersionUID = -3120617863591563455L; 44 45 72 protected Activatable(String location, 73 MarshalledObject data, 74 boolean restart, 75 int port) 76 throws ActivationException , RemoteException 77 { 78 super(); 79 id = exportObject(this, location, data, restart, port); 80 } 81 82 112 protected Activatable(String location, 113 MarshalledObject data, 114 boolean restart, 115 int port, 116 RMIClientSocketFactory csf, 117 RMIServerSocketFactory ssf) 118 throws ActivationException , RemoteException 119 { 120 super(); 121 id = exportObject(this, location, data, restart, port, csf, ssf); 122 } 123 124 144 protected Activatable(ActivationID id, int port) 145 throws RemoteException 146 { 147 super(); 148 this.id = id; 149 exportObject(this, id, port); 150 } 151 152 175 protected Activatable(ActivationID id, int port, 176 RMIClientSocketFactory csf, 177 RMIServerSocketFactory ssf) 178 throws RemoteException 179 { 180 super(); 181 this.id = id; 182 exportObject(this, id, port, csf, ssf); 183 } 184 185 192 protected ActivationID getID() { 193 return id; 194 } 195 196 208 public static Remote register(ActivationDesc desc) 209 throws UnknownGroupException , ActivationException , RemoteException 210 { 211 ActivationID id = 213 ActivationGroup.getSystem().registerObject(desc); 214 return sun.rmi.server.ActivatableRef.getStub(desc, id); 215 } 216 217 242 public static boolean inactive(ActivationID id) 243 throws UnknownObjectException , ActivationException , RemoteException 244 { 245 return ActivationGroup.currentGroup().inactiveObject(id); 246 } 247 248 259 public static void unregister(ActivationID id) 260 throws UnknownObjectException , ActivationException , RemoteException 261 { 262 ActivationGroup.getSystem().unregisterObject(id); 263 } 264 265 298 public static ActivationID exportObject(Remote obj, 299 String location, 300 MarshalledObject data, 301 boolean restart, 302 int port) 303 throws ActivationException , RemoteException 304 { 305 ActivationDesc desc = new ActivationDesc (obj.getClass().getName(), 306 location, data, restart); 307 ActivationID id = ActivationGroup.getSystem().registerObject(desc); 308 Remote stub = exportObject(obj, id, port); 309 ActivationGroup.currentGroup().activeObject(id, obj); 310 return id; 311 } 312 313 349 public static ActivationID exportObject(Remote obj, 350 String location, 351 MarshalledObject data, 352 boolean restart, 353 int port, 354 RMIClientSocketFactory csf, 355 RMIServerSocketFactory ssf) 356 throws ActivationException , RemoteException 357 { 358 ActivationDesc desc = new ActivationDesc (obj.getClass().getName(), 359 location, data, restart); 360 ActivationID id = ActivationGroup.getSystem().registerObject(desc); 361 Remote stub = exportObject(obj, id, port, csf, ssf); 362 ActivationGroup.currentGroup().activeObject(id, obj); 363 return id; 364 } 365 366 387 public static Remote exportObject(Remote obj, 388 ActivationID id, 389 int port) 390 throws RemoteException 391 { 392 return exportObject(obj, new ActivatableServerRef(id, port)); 393 } 394 395 419 public static Remote exportObject(Remote obj, 420 ActivationID id, 421 int port, 422 RMIClientSocketFactory csf, 423 RMIServerSocketFactory ssf) 424 throws RemoteException 425 { 426 return exportObject(obj, new ActivatableServerRef(id, port, csf, ssf)); 427 } 428 429 447 public static boolean unexportObject(Remote obj, boolean force) 448 throws NoSuchObjectException 449 { 450 return sun.rmi.transport.ObjectTable.unexportObject(obj, force); 451 } 452 453 456 private static Remote exportObject(Remote obj, ActivatableServerRef sref) 457 throws RemoteException 458 { 459 if (obj instanceof Activatable ) { 461 ((Activatable ) obj).ref = sref; 462 463 } 464 return sref.exportObject(obj, null, false); 465 } 466 } 467 | Popular Tags |