FileDocCategorySizeDatePackage
NewBetterMsgHandler.javaAPI DocExample1716Sun Nov 03 18:30:48 GMT 1996dcj.examples.messageV2

BasicMsgHandler

public abstract class BasicMsgHandler extends Object implements Runnable

Fields Summary
public static BasicMsgHandler
current
InputStream
msgIn
OutputStream
msgOut
StreamTokenizer
tokenizer
Constructors Summary
public BasicMsgHandler(InputStream in, OutputStream out)


       
    setStreams(in, out);
    current = this;
  
Methods Summary
protected abstract BasicMessagebuildMessage(java.lang.String msgId)

public BasicMessagereadMsg()

    BasicMessage msg;
    String token;
    DataInputStream din = new DataInputStream(msgIn);

    // Get message ID and build corresponding BasicMessage
    token = din.readUTF();
    msg = buildMessage(token);

    // Tell message to read its args
    if (msg != null && msg.readArgs(msgIn))
      return msg;
    else
      return null;
  
public voidrun()

    try {
      while (true) {
        BasicMessage msg = readMsg();
        if (msg != null)
          msg.Do();
      }
    }
    // Treat an IOException as a termination of the message
    // exchange, and let this message-processing thread die.
    catch (IOException e) {}
  
public voidsendMsg(BasicMessage msg)

    boolean success = true;
    DataOutputStream dout = new DataOutputStream(msgOut);

    // Send message ID
    dout.writeUTF(msg.messageID());

    // Tell message to send its arguments
    msg.writeArgs(msgOut);
  
protected voidsetStreams(java.io.InputStream in, java.io.OutputStream out)

    msgIn = in;
    msgOut = out;