Requirements:
Disadvantage: very long.
Problem: Java hides process identifiers.
Disadvantage: processes only importing objects must open a port anyway.
A space identifies a Java process allocating or referencing network
objects.
class Space implements Serializable {
InetAddress iaddr; // IP number of the processor
int port; // socket port for opening connections
... methods hashCode and equals for using ...
... spaces as keys in hash tables ...
... toString for printing spaces ...
}
The wire representation is assigned the first time a network object
is sent to any other process.
class WireRep implements Serializable {
Space sp; // The process owner of the represented network object
long id; // The object identification within the process
String stubClassName; // For convenience
... hashCode, equals and toString ...
... readResolve ...
}
Writing process:
Reading process:
OutputStream out= ... ; // any output stream
ObjectOutputStream objOut= new ObjectOutputStream(out);
objOut.writeInt(i); // throws IOException
objOut.writeObject(space); // throws IOException
...
Inconvenience: must catch exceptions IOException, OptionalDataException
and ClassNotFoundException.
InputStream in= ... ; // any output stream
ObjectInputStream objIn= new ObjectInputStream(in);
int j= objIn.readInt();
Object space= objIn.readObject();
...
Any reference of a network object (local or remote) points to an object being a subclass of NetObjBase.
Network object are always passed by reference: when a network
object is written to an object stream, the object is replaced by its
wire representation.
abstract class NetObjBase implements NetObj {
WireRep wrep; // network identifier of the object
protected Object writeReplace() { // a hook
sendNetObj(this); // the object manager
return wrep;
}
}
When a wire representation if read from an object stream, it is
replaced by: (i) its concrete representation if it is found locally, or
(ii) a unique stub if it is remote reference.
class WireRep implements Serializable {
...
Object readResolve() {
return receiveNetObj(this); // the object manager
}
}