# HG changeset patch # User akahori # Date 1552386910 -32400 # Node ID 7d08e76d2553c60daccbed0d75bfafe9ae6b8822 # Parent e486c13d9ea9ddae833801bacbdf4aa4f18ea766# Parent 437f06e034b86767dc153a2eea4e4bfdf7bfb1d7 merge prefix tree diff -r e486c13d9ea9 -r 7d08e76d2553 src/main/java/christie/test/topology/treeTestTopology/StartTreeTestTopology.java diff -r e486c13d9ea9 -r 7d08e76d2553 src/test/java/christie/.DS_Store diff -r e486c13d9ea9 -r 7d08e76d2553 src/test/java/christie/example/PrefixTree/Calculate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/PrefixTree/Calculate.java Tue Mar 12 19:35:10 2019 +0900 @@ -0,0 +1,33 @@ +package christie.example.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); + } + } +} diff -r e486c13d9ea9 -r 7d08e76d2553 src/test/java/christie/example/PrefixTree/CheckMyName.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/PrefixTree/CheckMyName.java Tue Mar 12 19:35:10 2019 +0900 @@ -0,0 +1,22 @@ +package christie.example.PrefixTree; + +import christie.annotation.Peek; +import christie.annotation.Take; +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()); + } + } +} diff -r e486c13d9ea9 -r 7d08e76d2553 src/test/java/christie/example/PrefixTree/Child.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/PrefixTree/Child.java Tue Mar 12 19:35:10 2019 +0900 @@ -0,0 +1,21 @@ +package christie.example.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 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()); + } + + +} diff -r e486c13d9ea9 -r 7d08e76d2553 src/test/java/christie/example/PrefixTree/CountCalculate.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/PrefixTree/CountCalculate.java Tue Mar 12 19:35:10 2019 +0900 @@ -0,0 +1,30 @@ +package christie.example.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 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()); + } +} diff -r e486c13d9ea9 -r 7d08e76d2553 src/test/java/christie/example/PrefixTree/CountMessage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/PrefixTree/CountMessage.java Tue Mar 12 19:35:10 2019 +0900 @@ -0,0 +1,40 @@ +package christie.example.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()); + //child0,1へのメッセージ送信はできてる。 + } + + cgm.setup(new CountCalculate()); + }else{ + cgm.setup(new CountMessage()); + put("count",count); + } + + } +} diff -r e486c13d9ea9 -r 7d08e76d2553 src/test/java/christie/example/PrefixTree/ReceiveMessage.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/PrefixTree/ReceiveMessage.java Tue Mar 12 19:35:10 2019 +0900 @@ -0,0 +1,17 @@ +package christie.example.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()); + } +} diff -r e486c13d9ea9 -r 7d08e76d2553 src/test/java/christie/example/PrefixTree/RelayStart.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/PrefixTree/RelayStart.java Tue Mar 12 19:35:10 2019 +0900 @@ -0,0 +1,28 @@ +package christie.example.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 java.util.regex.Pattern; + +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()); + } +} diff -r e486c13d9ea9 -r 7d08e76d2553 src/test/java/christie/example/PrefixTree/Root.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/PrefixTree/Root.java Tue Mar 12 19:35:10 2019 +0900 @@ -0,0 +1,18 @@ +package christie.example.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()); + } +} diff -r e486c13d9ea9 -r 7d08e76d2553 src/test/java/christie/example/PrefixTree/StartPrefixTree.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/PrefixTree/StartPrefixTree.java Tue Mar 12 19:35:10 2019 +0900 @@ -0,0 +1,40 @@ +package christie.example.PrefixTree; + +import christie.codegear.CodeGearManager; +import christie.codegear.StartCodeGear; +import christie.topology.manager.StartTopologyManager; +import christie.topology.manager.TopologyManagerConfig; +import christie.topology.node.StartTopologyNode; +import christie.topology.node.TopologyNodeConfig; + +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 = 10; + 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)}; + TopologyNodeConfig nodeConfig = new TopologyNodeConfig(nodeArg); + StartTopologyNode startTopologyNode = new StartTopologyNode(nodeConfig, new CheckMyName()); + startTopologyNode.put("num", i); + startTopologyNode.put("totalNodeNum", nodeNum - 1);//rootを除いた分のノード数 + } + + + } + +} diff -r e486c13d9ea9 -r 7d08e76d2553 src/test/java/christie/example/PrefixTree/sendOrDisplay.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/PrefixTree/sendOrDisplay.java Tue Mar 12 19:35:10 2019 +0900 @@ -0,0 +1,24 @@ +package christie.example.PrefixTree; + +import christie.annotation.Peek; +import christie.annotation.Take; +import christie.codegear.CodeGear; +import christie.codegear.CodeGearManager; +import christie.topology.TopologyDataGear; + +public class sendOrDisplay extends CodeGear { + @Take + int num; + + @Peek + TopologyDataGear topoDG; + + @Override + protected void run(CodeGearManager cgm) { + if(topoDG.getConnectionList().contains("parent")){ + put("parent", "pushedNum", num); + }else{ + System.out.println("total:" + num); + } + } +}