NexusRMI object serialization

NexusRMI allows the specification of the object serialization protocol on a per remote object basis. The RMI API has been slightly extended to support this. Original RMI programs will still work and will be assigned a default serialization protocol. We built NexusRMI based on the JDK 1.1 API; this document will therefore assume the JDK 1.1 API as the base API.

To support our object serialization framework, the definition of the UnicastRemoteObject class has one constructor and one method added to it. Our definition of the UnicastRemoteObject class looks as follows:

package nexusrmi.server;

import nexusrmi.*;

public class UnicastRemoteObject extends RemoteServer {
    protected UnicastRemoteObject() throws RemoteException {...}
    protected UnicastRemoteObject(Serialize ser) throws RemoteException {...}

    public static RemoteStub exportObject(Remote obj) throws RemoteException {...}
    public static RemoteStub exportObject(Remote obj, Serialize ser) throws RemoteException {...}

    public Object clone() throws CloneNotSupportedException {...}
}

The class Serialize is defined in package nexusrmi and looks as follows:

package nexusrmi;

public abstract class Serialize {
    ...
    public void initWrite() {...}
    public void initRead(Object buffer, String codebase) {...}

    public void startWriteHeader() { }
    public void startReadHeader() { }
    public void startWriteData() { }
    public void startReadData() { }

    public final void writeHPCxxHeaderStartpoint(Startpoint sp) {...}
    public final void writeHPCxxHeaderOffset(int off) {...}
    public final void writeHPCxxHeaderHandlerid(int id) {...}
    public final Startpoint readHPCxxHeaderStartpoint() {...}
    public final int readHPCxxHeaderOffset() {...}
    public final int readHPCxxHeaderHandlerid() {...}

    public Object getBuffer() {...}

    public void writeboolean(boolean b) {...}
    public boolean readboolean() {...}

    public void writebyte(byte b) {...}
    public byte readbyte() {...}

    public void writechar(char c) {...}
    public char readchar() {...}

    public void writeshort(short s) {...}
    public short readshort() {...}

    public void writeint(int i) {...}
    public int readint() {...}

    public void writelong(long l) {...}
    public long readlong() {...}

    public void writefloat(float f) {...}
    public float readfloat() {...}

    public void writedouble(double d) {...}
    public double readdouble() {...}

    public void writeObject(Object o) {...}
    public Object readObject(Object caller, Object container) {...}

    public void writeFinalObject(Class type, Object o) {...}
    public Object readFinalObject(Class type, Object caller, Object container) {...}
}

To implement a custom serialization protocol, extend this class (or any other class that extends this class) and override those methods needed to implement your serialization protocol. For examples, check out the default serialization protocol Nexusize in package nexusrmi. This protocol can handle all kinds of object graphs and will reconstruct the exact same graph structure on the receiving side.

The class PutBuffer is used to serialize objects into. It provides methods to write all primitive types (except boolean) and arrays of these. Objects are deserialized from a GetBuffer, which provides the read methods corresponding to the PutBuffer write methods. The PutBuffer and GetBuffer classes are defined in package nexus, which is included in this distribution.

To use your own serialization protocol, pass the object implementing the serialization protocol to either the UnicastRemoteObject constructor or the UnicastRemoteObject.exportObject() method and your protocol will be used for communication between this remote object and all its clients.


Fabian Breg
Last modified: Tue Mar 16 11:23:55 MET 1999