FileDocCategorySizeDatePackage
MediatorMessage.javaAPI DocExample2321Sun Feb 01 15:41:34 GMT 1998dcj.util.Collaborative

MediatorMessage

public class MediatorMessage extends Message
Source code from "Java Distributed Computing", by Jim Farley. Class: MediatorMessage Example: 9-6 Description: Subclass of Message that handles messages for our collaboration framework.

Fields Summary
protected Mediator
mediator
Constructors Summary
public MediatorMessage(Mediator m)


     
    mediator = m;
  
public MediatorMessage(String mid)

    super(mid);
  
Methods Summary
public booleanDo()

    boolean success = false;

    try {
      String mtype = messageID();
      if (mtype.compareTo("send") == 0) {
        Identity from = (Identity)getArg(0);
        Identity to = (Identity)getArg(1);
        String tag = (String)getArg(2);
        try {
          String s = (String)getArg(3);
          mediator.send(to, from, tag, s);
          success = true;
        }
        catch (ClassCastException cce) {
          // Argument wasn't a String, so send it as an Object
          Object oarg = getArg(3);
          mediator.send(to, from, tag, oarg);
          success = true;
        }
      }
      else if (mtype.compareTo("broadcast") == 0) {
        System.out.println("mm: Got broadcast message.");
        Identity from = (Identity)getArg(0);
        String tag = (String)getArg(1);
        System.out.println("mm: tag = \"" + tag + "\"");
        try {
          String s = (String)getArg(2);
          mediator.broadcast(from, tag, s);
          success = true;
        }
        catch (ClassCastException cce) {
          Object oarg = getArg(2);
          mediator.broadcast(from, tag, oarg);
        }
      }
    }
    catch (Exception e) {
      success = false;
      System.out.println("mm: Error parsing message.");
      e.printStackTrace();
    }
    return success;
  
public booleanhandles(java.lang.String msgId)

 return true; 
public MessagenewCopy()

    MediatorMessage copy;
    if (mediator != null) {
      // Make a new MediatorMessage with the same Mediator
      copy = new MediatorMessage(mediator);
      copy.setId(messageID());
    }
    else {
      copy = new MediatorMessage(messageID());
    }
    return copy;