[Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/wustl/tools/java/edu/wustl/mobilab/agilla
Tester.java, 1.5, 1.6
Chien-Liang Fok
chien-liang at users.sourceforge.net
Wed Sep 20 03:55:48 PDT 2006
Update of /cvsroot/tinyos/tinyos-1.x/contrib/wustl/tools/java/edu/wustl/mobilab/agilla
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv570
Modified Files:
Tester.java
Log Message:
group comm chat
Index: Tester.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/wustl/tools/java/edu/wustl/mobilab/agilla/Tester.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Tester.java 17 Nov 2005 23:24:59 -0000 1.5
--- Tester.java 20 Sep 2006 10:55:46 -0000 1.6
***************
*** 10,13 ****
--- 10,16 ----
import java.io.File;
import java.io.FileReader;
+ import java.util.*;
+ import javax.swing.JOptionPane;
+ import javax.swing.JFrame;
import edu.wustl.mobilab.agilla.messages.AgillaRxnMsgJ;
***************
*** 183,251 ****
// }
public void run() {
! String code = "";
! try {
! String fileName = AgillaProperties.getProperties().getInitDir()
! + "\\" + "3Blink.ma";
! dbg("Reading agent: " + fileName);
!
! File f = new File(fileName);
! FileReader fr = new FileReader(f);
! BufferedReader br = new BufferedReader(fr);
!
! String curr;
! while ((curr = br.readLine()) != null) {
! code += curr + "\n";
! }
! br.close();
! fr.close();
! } catch (Exception e) {
! e.printStackTrace();
! System.exit(1);
! }
! Agent agent = new Agent(code);
! /** Add 5 things to the stack **/
! for (int i = 0; i < 5; i++) {
! try {
! agent.getOpStack().add(new AgillaValue((short)i));
! } catch (OpStackException e) {
! e.printStackTrace();
}
! }
! /** Add a variable to the heap **/
! AgillaStackVariable[] heap = agent.getHeap();
! for (int i = 0; i < AgillaConstants.AGILLA_HEAP_SIZE; i++) {
! if (heap[i].getType() == AgillaConstants.AGILLA_TYPE_INVALID) {
! heap[i] = new AgillaValue((short)i);
! continue;
}
! }
!
! /** Add a reaction **/
!
! AgillaRxnMsgJ [] oldRxns = agent.getRxns();
! AgillaRxnMsgJ [] newRxns = new AgillaRxnMsgJ [oldRxns.length+1];
! System.arraycopy(oldRxns, 0, newRxns, 0, oldRxns.length);
- Tuple t = new Tuple();
- t.addField(new AgillaValue((short)1));
! newRxns[newRxns.length-1] = new AgillaRxnMsgJ((short)(newRxns.length-1),
! new edu.wustl.mobilab.agilla.Reaction(agent.getID(), 1, t));
! agent.setReactions(newRxns);
- dbg("Agent: " + agent);
- try {
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- dbg("Injecting agent...");
- injector.inject(agent, 0);
}
--- 186,324 ----
// }
+ // public void run() {
+ // String code = "";
+ // try {
+ // String fileName = AgillaProperties.getProperties().getInitDir()
+ // + "\\" + "3Blink.ma";
+ // dbg("Reading agent: " + fileName);
+ //
+ // File f = new File(fileName);
+ // FileReader fr = new FileReader(f);
+ // BufferedReader br = new BufferedReader(fr);
+ //
+ // String curr;
+ // while ((curr = br.readLine()) != null) {
+ // code += curr + "\n";
+ // }
+ // br.close();
+ // fr.close();
+ // } catch (Exception e) {
+ // e.printStackTrace();
+ // System.exit(1);
+ // }
+ //
+ // Agent agent = new Agent(code);
+ //
+ // /** Add 5 things to the stack **/
+ // for (int i = 0; i < 5; i++) {
+ // try {
+ // agent.getOpStack().add(new AgillaValue((short)i));
+ // } catch (OpStackException e) {
+ // e.printStackTrace();
+ // }
+ // }
+ //
+ // /** Add a variable to the heap **/
+ // AgillaStackVariable[] heap = agent.getHeap();
+ // for (int i = 0; i < AgillaConstants.AGILLA_HEAP_SIZE; i++) {
+ // if (heap[i].getType() == AgillaConstants.AGILLA_TYPE_INVALID) {
+ // heap[i] = new AgillaValue((short)i);
+ // continue;
+ // }
+ // }
+ //
+ // /** Add a reaction **/
+ //
+ // AgillaRxnMsgJ [] oldRxns = agent.getRxns();
+ // AgillaRxnMsgJ [] newRxns = new AgillaRxnMsgJ [oldRxns.length+1];
+ // System.arraycopy(oldRxns, 0, newRxns, 0, oldRxns.length);
+ //
+ // Tuple t = new Tuple();
+ // t.addField(new AgillaValue((short)1));
+ //
+ // newRxns[newRxns.length-1] = new AgillaRxnMsgJ((short)(newRxns.length-1),
+ // new edu.wustl.mobilab.agilla.Reaction(agent.getID(), 1, t));
+ // agent.setReactions(newRxns);
+ //
+ // dbg("Agent: " + agent);
+ //
+ // try {
+ // Thread.sleep(2000);
+ // } catch (InterruptedException e) {
+ // e.printStackTrace();
+ // }
+ //
+ // dbg("Injecting agent...");
+ // injector.inject(agent, 0);
+ // }
+
+ /**
+ * Sends chat messages.
+ */
public void run() {
! dbg("Running chat test...");
! dbg("Registering reaction sensitive to chat messages...");
! Tuple chatMsgTemplate = new Tuple();
! chatMsgTemplate.addField(new AgillaString("lbm"));
! chatMsgTemplate.addField(new AgillaType(AGILLA_TYPE_STRING));
! chatMsgTemplate.addField(new AgillaType(AGILLA_TYPE_STRING));
! Reaction chatMsgRxn = new Reaction(new AgillaAgentID(), 0, chatMsgTemplate);
! injector.getTS().registerReaction(chatMsgRxn,
! new ReactionListener() {
! public void reactionFired(Tuple t) {
! AgillaString name = (AgillaString)t.getField(1);
! AgillaString msg = (AgillaString)t.getField(2);
! dbg("Reacted to a message!\n\tName: " + name + "\n\tMessage: " + msg);
}
! });
! //JOptionPane.showMessageDialog(new JFrame(), "information",
! // "information", JOptionPane.INFORMATION_MESSAGE);
! /*dbg("Starting a timer that sends a chat message every 2 seconds.");
! new java.util.Timer().scheduleAtFixedRate(new TimerTask() {
! public void run() {
!
! Tuple chatMsg = new Tuple();
! chatMsg.addField(new AgillaString("snd"));
! chatMsg.addField(new AgillaString("aaa"));
! chatMsg.addField(new AgillaString("hel"));
! dbg("Sending a chat message to 0: " + chatMsg);
!
! injector.getTS().rout(chatMsg, 0);
}
! }, 15000, 2000);*/
! // test the leader...
! new java.util.Timer().schedule(new TimerTask() {
! public void run() {
! dbg("Joining a group");
! Tuple joinMsg = new Tuple();
! joinMsg.addField(new AgillaString("jng"));
! joinMsg.addField(new AgillaLocation(UART_X, UART_Y));
! dbg("Sending a join message to 0: " + joinMsg);
!
! injector.getTS().rout(joinMsg, 0);
!
! new java.util.Timer().schedule(new TimerTask() {
! public void run() {
! dbg("Sending a member broadcast message to the leader");
! Tuple mbmMsg = new Tuple();
! mbmMsg.addField(new AgillaString("mbm"));
! mbmMsg.addField(new AgillaString("aaa"));
! mbmMsg.addField(new AgillaString("hel"));
! dbg("Member broadcast message: " + mbmMsg);
!
! injector.getTS().rout(mbmMsg, 0);
! }
! }, 3000);
!
! }
! }, 15000);
}
More information about the Tinyos-contrib-commits
mailing list