The Implementation of Network Objects

Requirements:


Process identification


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 ...
}


Object identification in a stream

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 ...
}


Object serialization

Java implements serialization by using reflection.

Writing process:

    OutputStream out= ... ; // any output stream
    ObjectOutputStream objOut= new ObjectOutputStream(out);
    objOut.writeInt(i);        // throws IOException
    objOut.writeObject(space); // throws IOException
    ...


Reading process:

    InputStream in= ... ; // any output stream
    ObjectInputStream objIn= new ObjectInputStream(in);
    int j= objIn.readInt();
    Object space= objIn.readObject();
    ...
Inconvenience: must catch exceptions IOException, OptionalDataException and ClassNotFoundException.


Implementation of writeObject


Dispatching the method put

    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;


Dispatching the method get

    // 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;