Mercurial > hg > Database > Christie
changeset 220:4e89fc999de9
add PrefixTree > main
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/test/topology/PrefixTree/Calculate.java Fri Mar 15 19:41:44 2019 +0900 @@ -0,0 +1,33 @@ +package christie.test.topology.PrefixTree; + +import christie.annotation.Peek; +import christie.annotation.Take; +import christie.codegear.CodeGear; +import christie.codegear.CodeGearManager; + +public class Calculate extends CodeGear { + @Take + int pushedNum; + + @Take + int num; + + @Take + int count; + + @Peek + int childNodeNum; + + @Override + protected void run(CodeGearManager cgm) { + num = num + pushedNum; + count ++; + put("num", num); + if(count >= childNodeNum){ + cgm.setup(new sendOrDisplay()); + }else{ + cgm.setup(new Calculate()); + put("count", count); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/test/topology/PrefixTree/CheckMyName.java Fri Mar 15 19:41:44 2019 +0900 @@ -0,0 +1,21 @@ +package christie.test.topology.PrefixTree; + +import christie.annotation.Peek; +import christie.codegear.CodeGear; +import christie.codegear.CodeGearManager; +import christie.topology.TopologyDataGear; + +public class CheckMyName extends CodeGear { + + @Peek + TopologyDataGear topoDG; + + @Override + protected void run(CodeGearManager cgm) { + if(topoDG.getNodeName().equals("node0")){ + cgm.setup(new Root()); + }else{ + cgm.setup(new Child()); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/test/topology/PrefixTree/Child.java Fri Mar 15 19:41:44 2019 +0900 @@ -0,0 +1,20 @@ +package christie.test.topology.PrefixTree; +import christie.annotation.Peek; +import christie.codegear.CodeGear; +import christie.codegear.CodeGearManager; +import christie.topology.Message; +import christie.topology.TopologyDataGear; + +public class Child extends CodeGear { + @Peek + TopologyDataGear topoDG; + + @Override + protected void run(CodeGearManager cgm) { + put("parent", "ack", new Message()); + cgm.setup(new ReceiveMessage()); + cgm.setup(new RelayStart()); + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/test/topology/PrefixTree/CountCalculate.java Fri Mar 15 19:41:44 2019 +0900 @@ -0,0 +1,28 @@ +package christie.test.topology.PrefixTree; + +import christie.annotation.Peek; +import christie.codegear.CodeGear; +import christie.codegear.CodeGearManager; +import christie.topology.TopologyDataGear; + +public class CountCalculate extends CodeGear { + @Peek + TopologyDataGear topoDG; + + @Override + protected void run(CodeGearManager cgm) { + int childNum = topoDG.getConnectionList().size(); + for(String nodeName : topoDG.getConnectionList()) { + if(nodeName.matches("parent")) { + childNum = childNum - 1; + } + + } + if (childNum == 0) { + put("pushedNum", 0); + } + put("count", 0); + put("childNodeNum", childNum); + cgm.setup(new Calculate()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/test/topology/PrefixTree/CountMessage.java Fri Mar 15 19:41:44 2019 +0900 @@ -0,0 +1,39 @@ +package christie.test.topology.PrefixTree; + +import christie.annotation.Peek; +import christie.annotation.Take; +import christie.codegear.CodeGear; +import christie.codegear.CodeGearManager; +import christie.topology.Message; +import christie.topology.TopologyDataGear; + +public class CountMessage extends CodeGear { + @Take + Message ack; + + @Peek + int totalNodeNum; + + @Peek + TopologyDataGear topoDG; + + @Take + int count; + + @Override + protected void run(CodeGearManager cgm) { + count ++; + if(count == totalNodeNum){ + System.out.print("success"); + for(String nodeName : topoDG.getConnectionList()) { + put(nodeName, "start", new Message()); + } + + cgm.setup(new CountCalculate()); + }else{ + cgm.setup(new CountMessage()); + put("count",count); + } + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/test/topology/PrefixTree/PrefixNode.java Fri Mar 15 19:41:44 2019 +0900 @@ -0,0 +1,17 @@ +package christie.test.topology.PrefixTree; + +import christie.topology.node.StartTopologyNode; +import christie.topology.node.TopologyNodeConfig; + +public class PrefixNode { + + public static void main(String[] args){ + PrefixTreeNodeConfig prefixTreeNodeConfig = new PrefixTreeNodeConfig(args); + int totalNodeNum = prefixTreeNodeConfig.getTotalNodeNum(); + + StartTopologyNode startTopologyNode = new StartTopologyNode((TopologyNodeConfig) prefixTreeNodeConfig, new CheckMyName()); + + startTopologyNode.put("num", prefixTreeNodeConfig.getI()); + startTopologyNode.put("totalNodeNum", totalNodeNum - 1); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/test/topology/PrefixTree/PrefixTreeNodeConfig.java Fri Mar 15 19:41:44 2019 +0900 @@ -0,0 +1,31 @@ +package christie.test.topology.PrefixTree; + +import christie.topology.node.TopologyNodeConfig; + +public class PrefixTreeNodeConfig extends TopologyNodeConfig { + + int totalNodeNum; + + int i; + + public PrefixTreeNodeConfig(String[] args) { + super(args); + for (int j = 0; j< args.length; j++) { + if ("--totalNodeNum".equals(args[j])) { + totalNodeNum = Integer.parseInt(args[++j]); + + }else if ("--i".equals(args[j])) { + i = Integer.parseInt(args[++j]); + + } + } + } + + public int getTotalNodeNum() { + return totalNodeNum; + } + + public int getI() { + return i; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/test/topology/PrefixTree/ReceiveMessage.java Fri Mar 15 19:41:44 2019 +0900 @@ -0,0 +1,17 @@ +package christie.test.topology.PrefixTree; + +import christie.annotation.Take; +import christie.codegear.CodeGear; +import christie.codegear.CodeGearManager; +import christie.topology.Message; + +public class ReceiveMessage extends CodeGear { + @Take + Message ack; + + @Override + protected void run(CodeGearManager cgm) { + put("parent", "ack", new Message()); + cgm.setup(new ReceiveMessage()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/test/topology/PrefixTree/RelayStart.java Fri Mar 15 19:41:44 2019 +0900 @@ -0,0 +1,26 @@ +package christie.test.topology.PrefixTree; + +import christie.annotation.Peek; +import christie.annotation.Take; +import christie.codegear.CodeGear; +import christie.codegear.CodeGearManager; +import christie.topology.Message; +import christie.topology.TopologyDataGear; + +public class RelayStart extends CodeGear { + @Take + Message start; + + @Peek + TopologyDataGear topoDG; + + @Override + protected void run(CodeGearManager cgm) { + for(String nodeName : topoDG.getConnectionList()) { + if(nodeName.matches("child" + ".*")) { + put(nodeName, "start", new Message()); + } + } + cgm.setup(new CountCalculate()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/test/topology/PrefixTree/Root.java Fri Mar 15 19:41:44 2019 +0900 @@ -0,0 +1,18 @@ +package christie.test.topology.PrefixTree; + +import christie.annotation.Peek; +import christie.codegear.CodeGear; +import christie.codegear.CodeGearManager; +import christie.topology.TopologyDataGear; + +public class Root extends CodeGear { + + @Peek + TopologyDataGear topoDG; + + @Override + protected void run(CodeGearManager cgm) { + put("count" , 0); + cgm.setup(new CountMessage()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/test/topology/PrefixTree/StartPrefixTree.java Fri Mar 15 19:41:44 2019 +0900 @@ -0,0 +1,45 @@ +package christie.test.topology.PrefixTree; + +import christie.codegear.CodeGearManager; +import christie.codegear.StartCodeGear; +import christie.topology.manager.StartTopologyManager; +import christie.topology.manager.TopologyManagerConfig; + +public class StartPrefixTree extends StartCodeGear { + + + public StartPrefixTree(CodeGearManager cgm) { + super(cgm); + } + + public static void main(String[] args) { + int topologyManagerPort = 10000; + int topologyNodePort = 10001; + int nodeNum = 8; + String[] managerArg = {"--localPort", String.valueOf(topologyManagerPort), "--Topology", "tree"}; + TopologyManagerConfig topologyManagerConfig = new TopologyManagerConfig(managerArg); + new StartTopologyManager(topologyManagerConfig); + //TopologyManagerの作成 + + for (int i = 0; i < nodeNum ; i++){ + String[] nodeArg = { + "--managerPort", String.valueOf(topologyManagerPort), //使うトポロジーマネージャーを選ぶ + "--managerHost", "localhost", + "--localPort", String.valueOf(topologyNodePort + i), + "--totalNodeNum", String.valueOf(nodeNum), + "--i", String.valueOf(i)}; + + PrefixNode.main(nodeArg); + + + + /*TopologyNodeConfig nodeConfig = new TopologyNodeConfig(nodeArg); + StartTopologyNode startTopologyNode = new StartTopologyNode(nodeConfig, new CheckMyName()); + startTopologyNode.put("num", i); + startTopologyNode.put("totalNodeNum", nodeNum - 1)*/;//rootを除いた分のノード数 + } + + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/test/topology/PrefixTree/sendOrDisplay.java Fri Mar 15 19:41:44 2019 +0900 @@ -0,0 +1,30 @@ +package christie.test.topology.PrefixTree; + +import christie.annotation.Peek; +import christie.annotation.Take; +import christie.codegear.CodeGear; +import christie.codegear.CodeGearManager; +import christie.topology.Message; +import christie.topology.TopologyDataGear; +import christie.topology.node.TopologyNodeConfig; + +public class sendOrDisplay extends CodeGear { + @Take + int num; + + @Peek + TopologyDataGear topoDG; + + @Peek + TopologyNodeConfig topologyNodeConfig; + + @Override + protected void run(CodeGearManager cgm) { + if(topoDG.getConnectionList().contains("parent")){ + put("parent", "pushedNum", num); + }else{ + System.out.println("total:" + num); + getDGM(topologyNodeConfig.getManagerKey()).put("FINISHMESSAGE", new Message()); + } + } +}