changeset 35:ac3b48c5f4da

share width each other with tree
author kazz <kazz@cr.ie.u-ryukyu.ac.jp>
date Fri, 20 Jan 2012 04:00:12 +0900
parents ca079a730d0b
children 0b25b48116b6
files .hgignore src/alice/test/topology/fish/CheckMyName.java src/alice/test/topology/fish/DistributedFish.java src/alice/test/topology/fish/FishConfig.java src/alice/test/topology/fish/Routing.java src/alice/test/topology/fish/RoutingTable.java src/alice/test/topology/fish/SendWidth.java src/alice/test/topology/fish/StartFish.java src/alice/test/topology/fish/WidthReceiver.java src/alice/topology/manager/ConfigWaiter.java src/alice/topology/manager/StartTopologyManager.java src/alice/topology/node/ConfigurationFinish.java src/alice/topology/node/Start.java
diffstat 13 files changed, 285 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Fri Jan 20 04:00:12 2012 +0900
@@ -0,0 +1,5 @@
+
+syntax: regexp
+^classes$
+syntax: regexp
+^Alice\.jar$
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/fish/CheckMyName.java	Fri Jan 20 04:00:12 2012 +0900
@@ -0,0 +1,45 @@
+package alice.test.topology.fish;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+public class CheckMyName extends CodeSegment {
+	
+	Receiver host = ids.create(CommandType.PEEK);
+	
+	@Override
+	public void run() {
+		String name = host.asString();
+		Pattern pattern = Pattern.compile("^(node|cli)([0-9]+)$");
+		Matcher matcher = pattern.matcher(name);
+		
+		matcher.find();
+		String type = matcher.group(1);
+		int num = new Integer(matcher.group(2));
+		
+		if (type.equals("cli")) {
+			System.out.println("I am client");
+			ods.update("local", "width", 400);
+		} else if (type.equals("node")) {
+			WidthReceiver cs = new WidthReceiver();
+			cs.widths.setKey("local", "widths");
+			cs.routing.setKey("local", "routing");
+			
+			ods.put("local", "routing", new RoutingTable());
+			if (num == 0) { // First node check
+				System.out.println("I am node0");
+				return;
+			}
+			System.out.println("I am node");
+		}
+		
+		SendWidth cs = new SendWidth();
+		cs.width.setKey("local", "width");
+
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/fish/DistributedFish.java	Fri Jan 20 04:00:12 2012 +0900
@@ -0,0 +1,13 @@
+package alice.test.topology.fish;
+
+import alice.topology.node.TopologyNode;
+
+public class DistributedFish {
+
+	public static void main(String[] args) {
+		FishConfig conf = new FishConfig(args);
+		TopologyNode node = new TopologyNode(conf, StartFish.class);
+
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/fish/FishConfig.java	Fri Jan 20 04:00:12 2012 +0900
@@ -0,0 +1,12 @@
+package alice.test.topology.fish;
+
+import alice.topology.node.TopologyNodeConfig;
+
+public class FishConfig extends TopologyNodeConfig {
+
+	public FishConfig(String[] args) {
+		super(args);
+		
+	}
+	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/fish/Routing.java	Fri Jan 20 04:00:12 2012 +0900
@@ -0,0 +1,36 @@
+package alice.test.topology.fish;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.msgpack.annotation.Message;
+import org.msgpack.annotation.Optional;
+
+@Message
+public class Routing {
+
+	public String name;
+	public int id;
+	public int width;
+	@Optional public int startX;
+	
+	public Routing() {}
+	
+	public Routing(String name, int width) {
+		this.name = name;
+		this.width = width;
+		System.out.println(name);
+		Pattern pattern = Pattern.compile("^child([0-9]+)$");
+		Matcher matcher = pattern.matcher(name);
+		matcher.find();
+		id = new Integer(matcher.group(1));
+	}
+
+	public Routing(String name, int id, int width, int startX) {
+		this.name = name;
+		this.id = id;
+		this.width = width;
+		this.startX = startX;
+	}
+	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/fish/RoutingTable.java	Fri Jan 20 04:00:12 2012 +0900
@@ -0,0 +1,14 @@
+package alice.test.topology.fish;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.msgpack.annotation.Message;
+
+@Message
+public class RoutingTable {
+
+	int sumWidth = 0;
+	List<Routing> table = new ArrayList<Routing>();
+	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/fish/SendWidth.java	Fri Jan 20 04:00:12 2012 +0900
@@ -0,0 +1,20 @@
+package alice.test.topology.fish;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+public class SendWidth extends CodeSegment {
+	
+	Receiver width = ids.create(CommandType.PEEK);
+
+	@Override
+	public void run() {
+		int width = this.width.asInteger();
+		ods.put("parent", "widths", width);
+		
+		SendWidth cs = new SendWidth();
+		cs.width.setKey("local", "width", this.width.index);
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/fish/StartFish.java	Fri Jan 20 04:00:12 2012 +0900
@@ -0,0 +1,13 @@
+package alice.test.topology.fish;
+
+import alice.codesegment.CodeSegment;
+
+public class StartFish extends CodeSegment {
+
+	@Override
+	public void run() {
+		CheckMyName cs = new CheckMyName();
+		cs.host.setKey("local", "host");
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/fish/WidthReceiver.java	Fri Jan 20 04:00:12 2012 +0900
@@ -0,0 +1,53 @@
+package alice.test.topology.fish;
+
+import java.util.Collections;
+import java.util.Comparator;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+public class WidthReceiver extends CodeSegment {
+	
+	public Receiver widths = ids.create(CommandType.TAKE);
+	public Receiver routing = ids.create(CommandType.PEEK);
+	
+	@Override
+	public void run() {
+		int width = this.widths.asInteger();
+		String from = this.widths.from;
+		RoutingTable routing = this.routing.asClass(RoutingTable.class);
+		Routing newRouting = new Routing(from, width);
+		boolean update = false;
+		for (Routing r : routing.table) {
+			if (r.id == newRouting.id) {
+				routing.sumWidth -= r.width;
+				routing.sumWidth += newRouting.width;
+				r.width = width;
+				update = true;
+				break;
+			}
+		}
+		if (!update) {
+			routing.table.add(newRouting);
+			Collections.sort(routing.table, new Comparator<Routing>() {
+				@Override
+				public int compare(Routing o1, Routing o2) {
+					return o1.id - o2.id;
+				}
+			});
+			routing.sumWidth += width;
+		}
+		
+		System.out.println(routing.sumWidth);
+		
+		ods.update("local", "width", routing.sumWidth);
+		ods.update("local", "routing", routing);
+		
+		WidthReceiver cs = new WidthReceiver();
+		cs.widths.setKey("local", "widths", this.widths.index);
+		cs.routing.setKey("local", "routing", this.routing.index);
+		
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/topology/manager/ConfigWaiter.java	Fri Jan 20 04:00:12 2012 +0900
@@ -0,0 +1,29 @@
+package alice.topology.manager;
+
+import org.msgpack.type.ValueFactory;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+public class ConfigWaiter extends CodeSegment {
+	
+	public Receiver done = ids.create(CommandType.TAKE);
+	public int count;
+	
+	public ConfigWaiter(int nodeNum) {
+		this.count = nodeNum;
+	}
+
+	@Override
+	public void run() {
+		count--;
+		if (count == 0) {
+			ods.put("local", "start", ValueFactory.createNilValue());
+			return;
+		}
+		ConfigWaiter cs3 = new ConfigWaiter(count);
+		cs3.done.setKey("local", "done");
+	}
+
+}
--- a/src/alice/topology/manager/StartTopologyManager.java	Thu Jan 19 16:01:50 2012 +0900
+++ b/src/alice/topology/manager/StartTopologyManager.java	Fri Jan 20 04:00:12 2012 +0900
@@ -30,6 +30,7 @@
 	public void run() {
 		LinkedList<String> nodeNames = new LinkedList<String>();
 		HashMap<String, LinkedList<NodeInfo>> topology = new HashMap<String, LinkedList<NodeInfo>>();
+		int nodeNum = 0;
 		try {
 			FileReader reader = new FileReader(new File(conf.confFilePath));
 			Parser parser = new Parser();
@@ -37,6 +38,7 @@
 			ArrayList<Graph> graphs = parser.getGraphs();
 			for (Graph graph : graphs) {
 				ArrayList<Node> nodes = graph.getNodes(false);
+				nodeNum = nodes.size();
 				for (Node node : nodes) {
 					String nodeName = node.getId().getId();
 					nodeNames.add(nodeName);
@@ -61,7 +63,6 @@
 					if (nodeInfo != null) {
 						nodeInfo.reverseName = connection;
 					}
-					
 				}
 			}
 			
@@ -78,6 +79,9 @@
 		
 		TopologyFinish cs2 = new TopologyFinish();
 		cs2.finish.setKey("local", "finish");
+		
+		ConfigWaiter cs3 = new ConfigWaiter(nodeNum);
+		cs3.done.setKey("local", "done");
 	}
 
 }
--- a/src/alice/topology/node/ConfigurationFinish.java	Thu Jan 19 16:01:50 2012 +0900
+++ b/src/alice/topology/node/ConfigurationFinish.java	Fri Jan 20 04:00:12 2012 +0900
@@ -1,5 +1,7 @@
 package alice.topology.node;
 
+import org.msgpack.type.ValueFactory;
+
 import alice.codesegment.CodeSegment;
 import alice.datasegment.CommandType;
 import alice.datasegment.Receiver;
@@ -17,16 +19,13 @@
 	@Override
 	public void run() {
 		if (reverseCount.val.equals(configNodeNum.val)) {
+			ods.put("manager", "done", ValueFactory.createNilValue());
+
 			System.out.println("Configuration finished");
-			if (clazz == null)
-				return;
-			try {
-				clazz.newInstance().execute();
-			} catch (InstantiationException e) {
-				e.printStackTrace();
-			} catch (IllegalAccessException e) {
-				e.printStackTrace();
-			}
+
+			Start cs = new Start(clazz);
+			cs.done.setKey("manager", "start");
+
 			return;
 		}
 		
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/topology/node/Start.java	Fri Jan 20 04:00:12 2012 +0900
@@ -0,0 +1,32 @@
+package alice.topology.node;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+public class Start extends CodeSegment {
+	
+	public Receiver done = ids.create(CommandType.PEEK);
+	
+	private Class<? extends CodeSegment> clazz;
+	
+	public Start(Class<? extends CodeSegment> clazz) {
+		this.clazz = clazz;
+	}
+	
+	@Override
+	public void run() {
+		System.out.println("Start!");
+		if (clazz == null)
+			return;
+		try {
+			clazz.newInstance().execute();
+		} catch (InstantiationException e) {
+			e.printStackTrace();
+		} catch (IllegalAccessException e) {
+			e.printStackTrace();
+		}
+
+	}
+
+}