FileDocCategorySizeDatePackage
Message.javaAPI DocExample2166Tue Jan 20 21:40:22 GMT 1998dcj.util.message

Message

public class Message extends Object
Source code from "Java Distributed Computing", by Jim Farley. Class: Message Example: 6-11 Description: The final version of the basic message class.

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


    
    id = "message";
    argList = new Vector();
  
public Message(String mid)

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

 return false; 
public voidaddArg(java.lang.Object arg)

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

    Vector listCopy = (Vector)argList.clone();
    return listCopy;
  
public java.lang.ObjectgetArg(int idx)

    Object arg = null;
    if (idx < argList.size()) {
      arg = argList.elementAt(idx);
    }

    return arg;
  
public booleanhandles(java.lang.String msgId)

 return false; 
public java.lang.StringmessageID()

    return id;
  
public MessagenewCopy()

 return new Message(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;
  
public 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;