[Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/wustl/tools/java/edu/wustl/mobilab/agilla/plugins
AgentGroupCommMgr.java, 1.3.2.1,
1.3.2.2 GroupCommChatPlugin.java, 1.5.2.1, 1.5.2.2
Chien-Liang Fok
chien-liang at users.sourceforge.net
Mon Nov 20 16:34:04 PST 2006
Update of /cvsroot/tinyos/tinyos-1.x/contrib/wustl/tools/java/edu/wustl/mobilab/agilla/plugins
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv13431/plugins
Modified Files:
Tag: GroupComm
AgentGroupCommMgr.java GroupCommChatPlugin.java
Log Message:
supports proxy
Index: AgentGroupCommMgr.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/wustl/tools/java/edu/wustl/mobilab/agilla/plugins/AgentGroupCommMgr.java,v
retrieving revision 1.3.2.1
retrieving revision 1.3.2.2
diff -C2 -d -r1.3.2.1 -r1.3.2.2
*** AgentGroupCommMgr.java 15 Nov 2006 04:30:39 -0000 1.3.2.1
--- AgentGroupCommMgr.java 21 Nov 2006 00:34:01 -0000 1.3.2.2
***************
*** 34,38 ****
// read in the leader agent
try {
! File f = new File(AgillaProperties.getProperties().getInitDir() + "/" + leader_file);
BufferedReader reader = new BufferedReader(new FileReader(f));
String nxtLine = reader.readLine();
--- 34,40 ----
// read in the leader agent
try {
! String fileName = AgillaProperties.getProperties().getInitDir() + "/" + leader_file;
! log("Opening leader file " + fileName);
! File f = new File(fileName);
BufferedReader reader = new BufferedReader(new FileReader(f));
String nxtLine = reader.readLine();
***************
*** 61,70 ****
AgillaLocation loc = (AgillaLocation)t.getField(2);
! log("Received a join message for group " + name + " from " + loc);
if (!leaderTable.containsKey(name)) {
leaderTable.put(name, loc);
injector.inject(new Agent(leaderString), loc.getAddr());
! log("Injected new leader for group " + name + " to " + loc);
}
--- 63,72 ----
AgillaLocation loc = (AgillaLocation)t.getField(2);
! log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n\nReceived a join message for group " + name + " from " + loc+ "\n\n\n");
if (!leaderTable.containsKey(name)) {
leaderTable.put(name, loc);
injector.inject(new Agent(leaderString), loc.getAddr());
! log("----------------------------------------------\n\n\nInjected new leader for group " + name + " to " + loc+ "\n\n\n" );
}
***************
*** 82,86 ****
! log("Sending reply " + leaderLoc + " to " + loc + ".");
ts.rout(reply, loc.getAddr());
}
--- 84,88 ----
! log("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n\nSending reply " + leaderLoc + " to " + loc + ".\n\n\n");
ts.rout(reply, loc.getAddr());
}
Index: GroupCommChatPlugin.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/wustl/tools/java/edu/wustl/mobilab/agilla/plugins/GroupCommChatPlugin.java,v
retrieving revision 1.5.2.1
retrieving revision 1.5.2.2
diff -C2 -d -r1.5.2.1 -r1.5.2.2
*** GroupCommChatPlugin.java 15 Nov 2006 04:30:39 -0000 1.5.2.1
--- GroupCommChatPlugin.java 21 Nov 2006 00:34:02 -0000 1.5.2.2
***************
*** 20,33 ****
*
* @author Chien-Liang Fok
- * @version 5/13/2003
*/
public class GroupCommChatPlugin extends Plugin implements java.io.Serializable, AgillaConstants {
- /**
- *
- */
private static final long serialVersionUID = -2670040562604730782L;
! private String member_file = "GroupComm/chat/Member.ma";
public static final String FONT_NAMES[] = {
--- 20,31 ----
*
* @author Chien-Liang Fok
*/
public class GroupCommChatPlugin extends Plugin implements java.io.Serializable, AgillaConstants {
private static final long serialVersionUID = -2670040562604730782L;
! private String member_file = "Member.ma";
! private String proxy_file = "Proxy.ma";
! private int initAddr = 0;
public static final String FONT_NAMES[] = {
***************
*** 38,51 ****
};
-
-
private AgentInjector injector;
! private Hashtable<AgillaAgentID, ChatGUI> memberGUITable = new Hashtable<AgillaAgentID, ChatGUI> ();
/**
* The address of the proxy that is attached to the base station.
*/
! private int proxy = 65530;
ChatGUI gui;
--- 36,47 ----
};
private AgentInjector injector;
! // private Hashtable<AgillaAgentID, ChatGUI> memberGUITable = new Hashtable<AgillaAgentID, ChatGUI> ();
/**
* The address of the proxy that is attached to the base station.
*/
! private char proxy_addr = 65530;
ChatGUI gui;
***************
*** 70,74 ****
String name = "unk";
this.injector = injector;
- boolean injectMember = false;
try {
for (int i = 0; i < args.length; i++) {
--- 66,69 ----
***************
*** 78,91 ****
throw new Exception("Invalid name, length must be 3.");
}
! else if (args[i].equals("-member")) {
this.member_file = args[++i];
! }
! else if (args[i].equals("-injectMember")) {
! injectMember = true;
! }
! else if (args[i].equals("-proxy")){
! proxy = Integer.valueOf(args[++i]).intValue();
! }
! else throw new Exception("Unknown parameter: " + args[i]);
}
} catch(Exception e) {
--- 73,85 ----
throw new Exception("Invalid name, length must be 3.");
}
! else if (args[i].equals("-member"))
this.member_file = args[++i];
! else if (args[i].equals("-proxy_file"))
! this.proxy_file = args[++i];
! else if (args[i].equals("-initAddr"))
! initAddr = Integer.valueOf(args[++i]); // The initial virtual address of the PDA
! else if (args[i].equals("-proxy")) {
! proxy_addr = (char)Integer.valueOf(args[++i]).intValue();
! } else throw new Exception("Unknown parameter: " + args[i]);
}
} catch(Exception e) {
***************
*** 94,97 ****
--- 88,96 ----
}
+ // set the initial virtual location of the PDA
+ if (initAddr != AgillaProperties.virtualID()) {
+ injector.setVID(initAddr);
+ }
+
gui = new ChatGUI(new AgillaString(name));
***************
*** 110,221 ****
gui.addText(name, msg);
}
! });
!
! // log("Registering reaction sensitive to create member chat GUI...");
! // Tuple CreateGUITemplate = new Tuple();
! // CreateGUITemplate.addField(new AgillaString("msc")); // member start chatting
! // CreateGUITemplate.addField(new AgillaType(AGILLA_TYPE_AGENTID));
! // CreateGUITemplate.addField(new AgillaType(AGILLA_TYPE_STRING));
! //
! // Reaction CreateGUIRxn = new Reaction(new AgillaAgentID(), 0, CreateGUITemplate);
! // injector.getTS().registerReaction(CreateGUIRxn, new ReactionListener() {
! // public void reactionFired(Tuple t){
! // AgillaAgentID agentID= (AgillaAgentID)t.getField(1);
! // AgillaString screenName = (AgillaString)t.getField(2);
! //
! // log("Reacted to a create GUI message!\n\t Screen Name: " + screenName + "\n\t Agent ID: " + agentID);
! // if(memberGUITable.containsKey(agentID))
! // log("Duplicate request, ignoring...");
! // else {
! // ChatGUI gui = new ChatGUI(agentID, screenName);
! // memberGUITable.put(agentID, gui);
! // }
! // }
! // });
!
! log("Registering reaction sensitive to dispose chat GUI...");
! Tuple killGUITemplate = new Tuple();
! killGUITemplate.addField(new AgillaString("msc")); // member start chatting
! killGUITemplate.addField(new AgillaType(AGILLA_TYPE_AGENTID));
! Reaction killGUIreaction = new Reaction(new AgillaAgentID(), 0, killGUITemplate);
! injector.getTS().registerReaction(killGUIreaction, new ReactionListener() {
! public void reactionFired(Tuple t){
! AgillaAgentID agentID= (AgillaAgentID)t.getField(1);
!
! log("Reacted to a kill GUI message!\n\t Agent ID: " + agentID);
! if(memberGUITable.containsKey(agentID)) {
! //memberGUITable.get(agentID).close();
! memberGUITable.remove(agentID).close();
! } else
! log("ERROR: Request to kill non-existant gui, ignoring...");
! }
! });
!
! if (injectMember) {
! String memberString = "";
! try {
! File f = new File(AgillaProperties.getProperties().getInitDir() + "/" + member_file);
! BufferedReader reader = new BufferedReader(new FileReader(f));
! String nxtLine = reader.readLine();
! while (nxtLine != null) {
! memberString += nxtLine + "\n";
! nxtLine = reader.readLine();
}
- } catch(Exception e) {
- e.printStackTrace();
- System.exit(1);
}
! Agent member = new Agent(memberString);
! member.setHeap(0, new AgillaString(name));
! injector.inject(member, 0);
}
! /*
! * Modify code to inject member code to the attached mote
! * need to find out the local address of the mote
! * */
!
! // frame = new JFrame();
! // frame.setTitle("Chat - " + name);
! //
! // initGUI();
}
! // public void reactionFired(Tuple t) {
! //
! // }
!
! /*public void agentArrived(){
! inTextString += "<i><font color=\"green\">[" +
! aID.getName() + " has re-engaged]</font></i><br>";
! setInText();
! otherPersonHere = true;
}
! public void agentLeft(){
! inTextString += "<i><font color=\"green\">[" +
! aID.getName() + " has disengaged]</font></i><br>";
! setInText();
! otherPersonHere = false;
! }*/
!
! // /**
! // * Returns true if the provided object is of type InstantMessagingGUI
! // * and contains the same AgentID as this one.
! // */
! // public boolean equals(Object o){
! // if (o instanceof GroupCommChatPlugin)
! // return ((GroupCommChatPlugin)o).getName().equals(name);
! // return false;
! // }
!
! // public String getName() {
! // return name;
! // }
!
!
!
!
!
private void log(String str){
--- 109,165 ----
gui.addText(name, msg);
}
! });
!
! injectProxy();
! injectMember();
! }
!
! private void setVID() {
! log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Setting virtual address of proxy to be " + initAddr + "....");
! injector.setVID(initAddr);
! try {
! for (int i = 0; i < 20; i++) {
! System.out.println("Waiting " + i + " of 20 seconds...");
! synchronized(this) {
! wait(1000);
}
}
! } catch(Exception e) {
! e.printStackTrace();
}
! log("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Virtual address has been set.");
}
! private void injectProxy() {
! String proxyFile = AgillaProperties.getProperties().getInitDir() + "/" + proxy_file;
! log("Proxy file: " + proxyFile);
! Agent proxy = loadAgent(proxyFile);
! injector.inject(proxy, proxy_addr);
}
! private void injectMember() {
! String memberFile = AgillaProperties.getProperties().getInitDir() + "/" + member_file;
! log("Member file: " + memberFile);
! Agent member = loadAgent(memberFile);
! member.setHeap(0, new AgillaValue((short)proxy_addr));
! injector.inject(member, proxy_addr);
! }
+ private Agent loadAgent(String agentFile) {
+ String agentString = "";
+ try {
+ File f = new File(agentFile);
+ BufferedReader reader = new BufferedReader(new FileReader(f));
+ String nxtLine = reader.readLine();
+ while (nxtLine != null) {
+ agentString += nxtLine + "\n";
+ nxtLine = reader.readLine();
+ }
+ } catch(Exception e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ return new Agent(agentString);
+ }
private void log(String str){
***************
*** 227,231 ****
*/
public void reset() {
!
}
--- 171,178 ----
*/
public void reset() {
! // set the initial virtual location of the PDA
! setVID();
! injectProxy();
! injectMember();
}
***************
*** 520,525 ****
chatMsg.addField(new AgillaString(outMessage));
! log("Sending a chat message to : " + proxy + " message = " + chatMsg);
! injector.getTS().rout(chatMsg, proxy);
outText.setText("");
--- 467,474 ----
chatMsg.addField(new AgillaString(outMessage));
! int dest = 0;
! dest |= proxy_addr;
! log("Sending a chat message to : " + dest + " message = " + chatMsg);
! injector.getTS().rout(chatMsg, dest);
outText.setText("");
More information about the Tinyos-contrib-commits
mailing list