FileDocCategorySizeDatePackage
BetterMessage.javaAPI DocExample1926Tue Jan 20 21:16:52 GMT 1998dcj.examples.messageV2

BasicMessage

public abstract class BasicMessage extends Object
Source code from "Java Distributed Computing", by Jim Farley. Class: BasicMessage Example: 6-6 Description: An updated version of the BasicMessage that handles heterogeneous argument lists.

Fields Summary
protected String
id
protected Vector
argList
String
endToken
Constructors Summary
public BasicMessage()


    
    argList = new Vector();
  
public BasicMessage(String mid)

    id = mid;
    argList = new Vector();
  
Methods Summary
public abstract booleanDo()

public voidaddArg(java.lang.Object arg)

    argList.addElement(arg);
  
public java.util.VectorargList()

    Vector listCopy = (Vector)argList.clone();
    return listCopy;
  
public java.lang.StringmessageID()

    return id;
  
public booleanreadArgs(java.io.InputStream ins)

    boolean success = true;
    DataInputStream din = new DataInputStream(ins);

    // Read tokens until the "end-of-message" token is seen.
    try {
      String token = din.readUTF();
      while (token.compareTo(endToken) != 0) {
        addArg(token);
        token = din.readUTF();
      }
    }
    catch (IOException e) {
      // Failed to read complete argument list.
      success = false;
    }
    return success;
  
protected voidsetId(java.lang.String mid)

    id = mid;
  
public booleanwriteArgs(java.io.OutputStream outs)

    int len = argList.size();
    boolean success = true;
    DataOutputStream dout = new DataOutputStream(outs);

    // Write each argument in order
    try {
      for (int i = 0; i < len; i++) {
        String arg = (String)argList.elementAt(i);
        dout.writeUTF(arg);
      }

      // Finish with the end-of-message token
      dout.writeUTF(endToken);
    }
    catch (IOException e) {
      success = false;
    }
    return success;