Requirements:
Disadvantage: very long.
Problem: Java hides process identifier.
Disadvantage: processes only importing objects must open a port anyway.
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 ...
}
class WireRep implements Serializable {
Space sp; // The process owner of the represented network object
long id; // The object identification withing the process
String stubClassName;
... hashCode, equals and toString ...
... readResolve ...
}
Writing process:
OutputStream out= ... ; // any output stream
ObjectOutputStream objOut= new ObjectOutputStream(out);
objOut.writeInt(i); // throws IOException
objOut.writeObject(space); // throws IOException
...
Reading process:
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();
...
Object o= (Object)in.readObject(); // get the parameter
client.checkTag(); // not really needed
try {
server.put(o); // invoke the method
}
catch (Exception excp) {
client.remoteRetException(excp);
return;
}
client.remoteRetVoid();
return;
// No parameters
client.checkTag();
Object o= null; // for the value returned
try {
o= server.get(); // invoke the method
}
catch (Exception excp) {
client.remoteRetException(excp);
return;
}
client.remoteRetObject(o);
return;