Serializing a network object

In Java, every class C defining the method writeReplace marks the class C being special. When an object o of class C is found, instead of writing the object o, the serialization writes o.writeReplace().

abstract class NetObjBase implements NetObj {
  WireRep wrep; // network identifier of the object

  protected Object writeReplace() { // a hook
    sendNetObj(this); // the object manager
    return wrep;
  }
}
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.


- 11 -