package umich.cbe.distview.demos; import java.lang.*; import java.util.*; import java.io.*; import umich.cbe.distview.io.*; import umich.cbe.distview.server.*; import umich.cbe.distview.util.DVApplet; /** * A ReceiverClient is a simple client which connects to the server, joins a * group and can only receive broadcast messages. A ReceiverClient is used * in conjunction with a TestClient to measure roundtrip delays for broadcast * messages in groups with multiple clients. Such a group contains multiple * ReceiverClients and only one TestClient, which broadcast messages and * measures the delays. */ public class ReceiverClient extends DVApplet { DVSharedState myGroup; public ReceiverClient(String hostName, int portNumber, String grpName) { serverHostName = hostName; serverPort = portNumber; appletGroupName = grpName; userName = "ReceiverClient"; } /** * This applet joins the group specified by the Session Manager. * The subclass should override this method to perform application- * specific operations, e.g., set a bcast handler and add shared * object, before joining. */ public void prepareToJoin(DVSharedState group) { RCBcastHandler cHandler = new RCBcastHandler(this); CBEDebug.debug("prepareToJoin called"); group.setBcastHandler(cHandler); myGroup = group; } /** * Notifies that this applet has successfully joined the specified group. */ public void joined(DVSharedState group) { group.setGroupProperty(DVGroupProperty.GROUP_TYPE, "Chat"); } public void hideApplet() {} public void killApplet() { stopSession(); } /** * Creates a new ReceiverClient. * @param args[] Group_name port# hostname */ public static void main(String args[]) { String grpname, grptype; int port, priority = 0; String host; if(args.length < 3){ System.out.println("Usage : ReceiverClient [Group_name] [port#] [hostname]"); //System.out.println("Usage : ReceiverClient [Group_name] [port#] [hostname] [priority]"); System.exit(0); } else { grpname = args[0]; try { port = Integer.parseInt(args[1],10); } catch(Exception e) { System.out.println("Defaulting to port 12345"); port = 12345; } host = args[2]; // a ReceiverClient may have a lower priority in the group try { priority = Integer.parseInt(args[3],10); } catch(Exception e) { System.out.println("Default priority = 5"); priority = 5; } ReceiverClient RC = new ReceiverClient(host, port, grpname); //CBEDebug.setLevel(0); RC.startSession(0, false); //if(priority < 5) { // RC.myGroup.inactivate(); //} } } } /** * The broadcast handler for the ReceiverClient class */ class RCBcastHandler extends DVBcastHandler { private ReceiverClient myApplet; public RCBcastHandler(ReceiverClient myApplet) { super(); this.myApplet = myApplet; } /** * Does nothing */ public void procBcastMsg(String senderGroup, Message aMsg) { //System.out.println("RC: message received"); } }