Writing Stubs and Skeletons

Serializing a method call

Writing the stub for a network buffer

The class ConcreteBuffer implements the network interface Buffer with the following methods:

    public interface Buffer extends NetObj {
      public void put(Object obj) throws NetException;
      public Object get() throws NetException;
    }
The stub for ConcreteBuffer must be named ConcreteBufferStub.

import netobj.*;
import java.io.*;

public class ConcreteBufferStub extends ConcreteNetObjStub
             implements Buffer {

  public void put(Object o) throws NetException {
    // Serialization for method put
  }

  public Object get() throws NetException {
    // Serialization for method get
  }

Serialization of method put

    ObjectOutputStream out= startRemoteCall(ConcreteBufferSkel.Put);
    try {
      out.writeObject(o); // One for each parameter
    }
    catch (IOException excp) {
      throwNetException(excp);
    }
    waitRemoteRetVoid();

Serialization of method get

    ObjectOutputStream out= startRemoteCall(ConcreteBufferSkel.Get);
    return waitRemoteRetObject();

The skeleton

The skeleton for ConcreteBuffer must be named ConcreteBufferSkel.

Writing the skeleton for the network buffer

import netobj.*;
import java.io.*;

public class ConcreteBufferSkel extends ConcreteNetObjSkel {
  final static int Put= 1; // method identifiers
  final static int Get= 2;
  public void dispatch(ObjectInputStream in, ClientConnection client,
                       ConcreteNetObj netObj, int methodId)
                       throws IOException, ClassNotFoundException {
    ConcreteBuffer server= (ConcreteBuffer)netObj;
    switch(methodId) {
      case Put: { ... } // dispatching of method put
      case Get: { ... } // dispatching of method get
} } }

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;