Methods Summary |
---|
public boolean | broadcast(Identity from, java.lang.String mtag, java.lang.Object o)
Message msg = new Message(mtag);
msg.addArg(from);
msg.addArg(o);
return mhandler.sendMsg(msg);
|
public boolean | broadcast(Identity from, java.lang.String mtag, java.lang.String s)
System.out.println("mm: Broadcasting message \"" + mtag + s + "\"");
Message msg = new Message(mtag);
msg.addArg(from);
msg.addArg(s);
return mhandler.sendMsg(msg);
|
public java.util.Vector | getMembers()
Vector members = new Vector();
Vector ids = mhandler.getAgentIds();
Enumeration e = ids.elements();
while (e.hasMoreElements()) {
Integer id = (Integer)e.nextElement();
Identity i = new Identity(id.intValue());
members.addElement(i);
}
return members;
|
protected void | initHandler()
// Add the mediator message "prototype" to the handler
Message m = new MediatorMessage(this);
mhandler.addMessageType(m);
|
public Identity | newMember()
int id = mhandler.nextAgentId();
Identity i = new Identity(id);
return i;
|
public boolean | remove(Identity i)
int id = i.getId();
boolean success = mhandler.removeAgent(id);
return success;
|
public void | run()
// Make the server socket
try {
socket = new ServerSocket(port);
}
catch (IOException e) {
System.out.println("Failed to bind to port " + port);
return;
}
System.out.println("Mediator running on port " + port);
// Listen for new clients...
while (true) {
try {
Socket clientConn = socket.accept();
Identity i = newMember();
mhandler.addAgent(i.getId(), clientConn.getInputStream(),
clientConn.getOutputStream());
System.out.println("Got new connection...");
Message imsg = new Message("identity");
imsg.addArg(i);
mhandler.sendMsg(imsg, i.getId());
}
catch (Exception e) {}
}
|
public boolean | send(Identity to, Identity from, java.lang.String mtag, java.lang.Object o)
Message msg = new Message(mtag);
msg.addArg(from);
msg.addArg(o);
return mhandler.sendMsg(msg, to.getId());
|
public boolean | send(Identity to, Identity from, java.lang.String mtag, java.lang.String s)
boolean success = false;
Message msg = new Message(mtag);
msg.addArg(from);
msg.addArg(s);
return mhandler.sendMsg(msg, to.getId());
|