FileDocCategorySizeDatePackage
ActivationID.javaAPI DocJava SE 5 API10188Fri Aug 26 14:57:12 BST 2005java.rmi.activation

ActivationID

public class ActivationID extends Object implements Serializable
Activation makes use of special identifiers to denote remote objects that can be activated over time. An activation identifier (an instance of the class ActivationID) contains several pieces of information needed for activating an object:
  • a remote reference to the object's activator (a {@link java.rmi.server.RemoteRef RemoteRef} instance), and
  • a unique identifier (a {@link java.rmi.server.UID UID} instance) for the object.

An activation identifier for an object can be obtained by registering an object with the activation system. Registration is accomplished in a few ways:

  • via the Activatable.register method
  • via the first Activatable constructor (that takes three arguments and both registers and exports the object, and
  • via the first Activatable.exportObject method that takes the activation descriptor, object and port as arguments; this method both registers and exports the object.
author
Ann Wollrath
version
1.28, 03/12/19
see
Activatable
since
1.2

Fields Summary
private transient Activator
activator
the object's activator
private transient UID
uid
the object's unique id
private static final long
serialVersionUID
indicate compatibility with the Java 2 SDK v1.2 version of class
Constructors Summary
public ActivationID(Activator activator)
The constructor for ActivationID takes a single argument, activator, that specifies a remote reference to the activator responsible for activating the object associated with this identifier. An instance of ActivationID is globally unique.

param
activator reference to the activator responsible for activating the object
since
1.2


                                                       
       
	this.activator = activator;
    
Methods Summary
public java.rmi.Remoteactivate(boolean force)
Activate the object for this id.

param
force if true, forces the activator to contact the group when activating the object (instead of returning a cached reference); if false, returning a cached value is acceptable.
return
the reference to the active remote object
exception
ActivationException if activation fails
exception
UnknownObjectException if the object is unknown
exception
RemoteException if remote call fails
since
1.2

 	try {
 	    MarshalledObject mobj =
		(MarshalledObject) activator.activate(this, force);
 	    return (Remote) mobj.get();
 	} catch (RemoteException e) {
 	    throw e;
 	} catch (IOException e) {
 	    throw new UnmarshalException("activation failed", e);
 	} catch (ClassNotFoundException e) {
 	    throw new UnmarshalException("activation failed", e);
	}
	
    
public booleanequals(java.lang.Object obj)
Compares two activation ids for content equality. Returns true if both of the following conditions are true: 1) the unique identifiers equivalent (by content), and 2) the activator specified in each identifier refers to the same remote object.

param
obj the Object to compare with
return
true if these Objects are equal; false otherwise.
see
java.util.Hashtable
since
1.2

	if (obj instanceof ActivationID) {
	    ActivationID id = (ActivationID) obj;
	    return (uid.equals(id.uid) && activator.equals(id.activator));
	} else {
	    return false;
	}
    
public inthashCode()
Returns a hashcode for the activation id. Two identifiers that refer to the same remote object will have the same hash code.

see
java.util.Hashtable
since
1.2

	return uid.hashCode();
    
private voidreadObject(java.io.ObjectInputStream in)
readObject for custom serialization.

This method reads this object's serialized form for this class as follows:

The readObject method is invoked on in to read this object's unique identifier (a {@link java.rmi.server.UID UID} instance).

Next, the readUTF method is invoked on in to read the external ref type name of the RemoteRef instance for this object's activator. Next, the RemoteRef instance is created of an implementation-specific class corresponding to the external ref type name (returned by readUTF), and the readExternal method is invoked on that RemoteRef instance to read the external form corresponding to the external ref type name.

Note: If the external ref type name is "UnicastRef", "UnicastServerRef", "UnicastRef2", "UnicastServerRef2", or "ActivatableRef", a corresponding implementation-specific class must be found, and its readExternal method must read the serial data for that external ref type name as specified to be written in the serialData documentation for this class. If the external ref type name is any other string (of non-zero length), a ClassNotFoundException will be thrown, unless the implementation provides an implementation-specific class corresponding to that external ref type name, in which case the RemoteRef will be an instance of that implementation-specific class.

	uid = (UID)in.readObject();
	
	try {
	    Class refClass = Class.forName(RemoteRef.packagePrefix + "." +
					   in.readUTF());
	    RemoteRef ref = (RemoteRef) refClass.newInstance();
	    ref.readExternal(in);
	    activator = (Activator)
		Proxy.newProxyInstance(null,
				       new Class[]{ Activator.class },
				       new RemoteObjectInvocationHandler(ref));

	} catch (InstantiationException e) {
	    throw (IOException)
		new InvalidObjectException(
		    "Unable to create remote reference").initCause(e);
	} catch (IllegalAccessException e) {
	    throw (IOException)
		new InvalidObjectException(
		    "Unable to create remote reference").initCause(e);
	}
    
private voidwriteObject(java.io.ObjectOutputStream out)
writeObject for custom serialization.

This method writes this object's serialized form for this class as follows:

The writeObject method is invoked on out passing this object's unique identifier (a {@link java.rmi.server.UID UID} instance) as the argument.

Next, the {@link java.rmi.server.RemoteRef#getRefClass(java.io.ObjectOutput) getRefClass} method is invoked on the activator's RemoteRef instance to obtain its external ref type name. Next, the writeUTF method is invoked on out with the value returned by getRefClass, and then the writeExternal method is invoked on the RemoteRef instance passing out as the argument.

serialData
The serialized data for this class comprises a java.rmi.server.UID (written with ObjectOutput.writeObject) followed by the external ref type name of the activator's RemoteRef instance (a string written with ObjectOutput.writeUTF), followed by the external form of the RemoteRef instance as written by its writeExternal method.

The external ref type name of the RemoteRef instance is determined using the definitions of external ref type names specified in the {@link java.rmi.server.RemoteObject RemoteObject} writeObject method serialData specification. Similarly, the data written by the writeExternal method and read by the readExternal method of RemoteRef implementation classes corresponding to each of the defined external ref type names is specified in the {@link java.rmi.server.RemoteObject RemoteObject} writeObject method serialData specification.

	out.writeObject(uid);

	RemoteRef ref;
	if (activator instanceof RemoteObject) {
	    ref = ((RemoteObject) activator).getRef();
	} else if (Proxy.isProxyClass(activator.getClass())) {
	    InvocationHandler handler = Proxy.getInvocationHandler(activator);
	    if (!(handler instanceof RemoteObjectInvocationHandler)) {
		throw new InvalidObjectException(
		    "unexpected invocation handler");
	    }
	    ref = ((RemoteObjectInvocationHandler) handler).getRef();
	    
	} else {
	    throw new InvalidObjectException("unexpected activator type");
	}
	out.writeUTF(ref.getRefClass(out));
	ref.writeExternal(out);