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;