# HG changeset patch # User kazz # Date 1326999612 -32400 # Node ID ac3b48c5f4da22094a270637edbe0216b1760633 # Parent ca079a730d0b6867ae973d08849d8499089c2c2e share width each other with tree diff -r ca079a730d0b -r ac3b48c5f4da .hgignore --- /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 diff -r ca079a730d0b -r ac3b48c5f4da src/alice/test/topology/fish/CheckMyName.java --- /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"); + + } + +} diff -r ca079a730d0b -r ac3b48c5f4da src/alice/test/topology/fish/DistributedFish.java --- /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); + + } + +} diff -r ca079a730d0b -r ac3b48c5f4da src/alice/test/topology/fish/FishConfig.java --- /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); + + } + +} diff -r ca079a730d0b -r ac3b48c5f4da src/alice/test/topology/fish/Routing.java --- /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; + } + +} diff -r ca079a730d0b -r ac3b48c5f4da src/alice/test/topology/fish/RoutingTable.java --- /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 table = new ArrayList(); + +} diff -r ca079a730d0b -r ac3b48c5f4da src/alice/test/topology/fish/SendWidth.java --- /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); + } + +} diff -r ca079a730d0b -r ac3b48c5f4da src/alice/test/topology/fish/StartFish.java --- /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"); + } + +} diff -r ca079a730d0b -r ac3b48c5f4da src/alice/test/topology/fish/WidthReceiver.java --- /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() { + @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); + + } + +} diff -r ca079a730d0b -r ac3b48c5f4da src/alice/topology/manager/ConfigWaiter.java --- /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"); + } + +} diff -r ca079a730d0b -r ac3b48c5f4da src/alice/topology/manager/StartTopologyManager.java --- 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 nodeNames = new LinkedList(); HashMap> topology = new HashMap>(); + int nodeNum = 0; try { FileReader reader = new FileReader(new File(conf.confFilePath)); Parser parser = new Parser(); @@ -37,6 +38,7 @@ ArrayList graphs = parser.getGraphs(); for (Graph graph : graphs) { ArrayList 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"); } } diff -r ca079a730d0b -r ac3b48c5f4da src/alice/topology/node/ConfigurationFinish.java --- 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; } diff -r ca079a730d0b -r ac3b48c5f4da src/alice/topology/node/Start.java --- /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 clazz; + + public Start(Class 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(); + } + + } + +}