Mercurial > hg > Members > tatsuki > Alice
changeset 45:ae24d5d40c10
add to calculate the time of RingTopology required
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 04 Feb 2012 14:31:07 +0900 |
parents | 73158dc54c59 |
children | 1a498f436332 |
files | src/alice/test/topology/ring/CheckMyName.java src/alice/test/topology/ring/FirstRingMessagePassing.java src/alice/test/topology/ring/RingMessagePassing.java src/alice/test/topology/ring/RingTopologyConfig.java src/alice/topology/node/Start.java |
diffstat | 5 files changed, 30 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/src/alice/test/topology/ring/CheckMyName.java Sat Feb 04 01:34:57 2012 +0900 +++ b/src/alice/test/topology/ring/CheckMyName.java Sat Feb 04 14:31:07 2012 +0900 @@ -1,5 +1,9 @@ package alice.test.topology.ring; +import java.util.Date; + +import org.apache.log4j.Logger; + import alice.codesegment.CodeSegment; import alice.datasegment.CommandType; import alice.datasegment.Receiver; @@ -7,20 +11,18 @@ public class CheckMyName extends CodeSegment { Receiver host = ids.create(CommandType.PEEK); - + Logger logger = Logger.getLogger(CheckMyName.class); @Override public void run() { String host = this.host.asString(); + logger.debug(host); if (host.equals("node0")) { - System.out.println("I am first node"); ods.put("local", "counter", 0); - FirstRingMessagePassing cs1 = new FirstRingMessagePassing(); + FirstRingMessagePassing cs1 = new FirstRingMessagePassing(new Date()); cs1.counter.setKey("local", "counter"); RingFinish cs2 = new RingFinish("manager"); cs2.finish.setKey("local", "finish"); - } else { - System.out.println("I am normal node"); ods.close("manager"); RingMessagePassing cs1 = new RingMessagePassing(); cs1.counter.setKey("local", "counter");
--- a/src/alice/test/topology/ring/FirstRingMessagePassing.java Sat Feb 04 01:34:57 2012 +0900 +++ b/src/alice/test/topology/ring/FirstRingMessagePassing.java Sat Feb 04 14:31:07 2012 +0900 @@ -1,7 +1,6 @@ package alice.test.topology.ring; -import java.net.InetAddress; -import java.net.UnknownHostException; +import java.util.Date; import org.msgpack.type.ValueFactory; @@ -11,28 +10,28 @@ public class FirstRingMessagePassing extends CodeSegment { - Receiver counter = ids.create(CommandType.TAKE); + public Receiver counter = ids.create(CommandType.TAKE); + public Date startTime; + + public FirstRingMessagePassing(Date startTime) { + this.startTime = startTime; + } @Override public void run() { int counter = this.counter.asInteger(); - - try { - System.out.print("[" + InetAddress.getLocalHost().getHostName() + "] "); - } catch (UnknownHostException e) { - e.printStackTrace(); - } - - System.out.println(++counter); - + ++counter; ods.put("right", "counter", counter); if (counter >= 10) { ods.put("right", "finish", ValueFactory.createNilValue()); + Date endTime = new Date(); + long time = endTime.getTime() - startTime.getTime(); + System.out.println(time); return; } - FirstRingMessagePassing cs = new FirstRingMessagePassing(); + FirstRingMessagePassing cs = new FirstRingMessagePassing(startTime); cs.counter.setKey("local", "counter"); }
--- a/src/alice/test/topology/ring/RingMessagePassing.java Sat Feb 04 01:34:57 2012 +0900 +++ b/src/alice/test/topology/ring/RingMessagePassing.java Sat Feb 04 14:31:07 2012 +0900 @@ -1,8 +1,5 @@ package alice.test.topology.ring; -import java.net.InetAddress; -import java.net.UnknownHostException; - import alice.codesegment.CodeSegment; import alice.datasegment.CommandType; import alice.datasegment.Receiver; @@ -14,14 +11,7 @@ @Override public void run() { int counter = this.counter.asInteger(); - - try { - System.out.print("[" + InetAddress.getLocalHost().getHostName() + "] "); - } catch (UnknownHostException e) { - e.printStackTrace(); - } - System.out.println(counter); - + ods.put("right", "counter", counter); RingMessagePassing cs = new RingMessagePassing();
--- a/src/alice/test/topology/ring/RingTopologyConfig.java Sat Feb 04 01:34:57 2012 +0900 +++ b/src/alice/test/topology/ring/RingTopologyConfig.java Sat Feb 04 14:31:07 2012 +0900 @@ -3,10 +3,14 @@ import alice.topology.node.TopologyNodeConfig; public class RingTopologyConfig extends TopologyNodeConfig { - + public int count = 10; public RingTopologyConfig(String[] args) { super(args); - + for (int i = 0; i< args.length; i++) { + if ("-count".equals(args[i])) { + this.count = new Integer(args[++i]); + } + } } }
--- a/src/alice/topology/node/Start.java Sat Feb 04 01:34:57 2012 +0900 +++ b/src/alice/topology/node/Start.java Sat Feb 04 14:31:07 2012 +0900 @@ -1,5 +1,7 @@ package alice.topology.node; +import org.apache.log4j.Logger; + import alice.codesegment.CodeSegment; import alice.datasegment.CommandType; import alice.datasegment.Receiver; @@ -7,7 +9,7 @@ public class Start extends CodeSegment { public Receiver done = ids.create(CommandType.PEEK); - + private Logger logger = Logger.getLogger(Start.class); private Class<? extends CodeSegment> clazz; public Start(Class<? extends CodeSegment> clazz) { @@ -16,7 +18,7 @@ @Override public void run() { - System.out.println("Start!"); + logger.info("Configuration finished."); if (clazz == null) return; try {