Mercurial > hg > Database > Christie
changeset 201:d15467cd08cc
add example PrefixTree
author | ichikitakahiro <e165713@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 25 Feb 2019 20:44:55 +0900 |
parents | 60afc98ce6a4 |
children | d0d1e5a9c39d |
files | src/test/java/christie/example/PrefixTree/Calculate.java src/test/java/christie/example/PrefixTree/CheckMyName.java src/test/java/christie/example/PrefixTree/Child.java src/test/java/christie/example/PrefixTree/ChildCodeGear.java src/test/java/christie/example/PrefixTree/CountMessage.java src/test/java/christie/example/PrefixTree/ParentCodeGear.java src/test/java/christie/example/PrefixTree/ReceiveMessage.java src/test/java/christie/example/PrefixTree/Root.java src/test/java/christie/example/PrefixTree/StartPrefixTree.java src/test/java/christie/example/PrefixTree/sendOrDisplay.java |
diffstat | 10 files changed, 172 insertions(+), 71 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/PrefixTree/Calculate.java Mon Feb 25 20:44:55 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; + +public class Calculate extends CodeGear { + @Take + int pushedNum; + + @Take + int num; + + @Override + protected void run(CodeGearManager cgm) { + num = num + pushedNum; + put("num", num); + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/PrefixTree/CheckMyName.java Mon Feb 25 20:44:55 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()); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/PrefixTree/Child.java Mon Feb 25 20:44:55 2019 +0900 @@ -0,0 +1,20 @@ +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()); + } + + +}
--- a/src/test/java/christie/example/PrefixTree/ChildCodeGear.java Mon Feb 25 16:40:17 2019 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -package christie.example.PrefixTree; - -import christie.annotation.Peek; -import christie.codegear.CodeGear; -import christie.codegear.CodeGearManager; -import christie.topology.TopologyDataGear; - -import java.util.List; - -public class ChildCodeGear extends CodeGear { - - @Peek - TopologyDataGear topoDG; - - @Override - protected void run(CodeGearManager cgm) { - List<String> _CLIST = topoDG.getConnectionList(); - if(_CLIST.contains("parent")) { - getDGM("parent").put("childNodeName", topoDG.getNodeName()); - //Conectionの中に"parent"があったらparentに自身のNodenameをputする。 - }else{ - getLocalDGM().put("countNodeName", 1); - cgm.setup(new ParentCodeGear()); - // - } - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/PrefixTree/CountMessage.java Mon Feb 25 20:44:55 2019 +0900 @@ -0,0 +1,38 @@ +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()); + } + cgm.setup(new Calculate()); + }else{ + cgm.setup(new CountMessage()); + put("count",count); + } + + } +}
--- a/src/test/java/christie/example/PrefixTree/ParentCodeGear.java Mon Feb 25 16:40:17 2019 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -package christie.example.PrefixTree; - -import christie.annotation.Peek; -import christie.annotation.Take; -import christie.codegear.CodeGear; -import christie.codegear.CodeGearManager; -import christie.topology.TopologyDataGear; -import christie.topology.node.TopologyNodeConfig; - -public class ParentCodeGear extends CodeGear { - @Peek - TopologyDataGear topoDG; - - @Peek - int maxNodeNum; - - @Peek - TopologyNodeConfig topologyNodeConfig; - - @Take - int countNodeNum; - - @Take - String childNodeName; - - @Override - protected void run(CodeGearManager cgm) { - System.out.println(topoDG.getNodeName() + " : " + childNodeName + " accept"); - if(countNodeNum == maxNodeNum){ - getDGM(topologyNodeConfig.getManagerKey()).put("finish", ""); - - } - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/PrefixTree/ReceiveMessage.java Mon Feb 25 20:44:55 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()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/PrefixTree/Root.java Mon Feb 25 20:44:55 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()); + } +}
--- a/src/test/java/christie/example/PrefixTree/StartPrefixTree.java Mon Feb 25 16:40:17 2019 +0900 +++ b/src/test/java/christie/example/PrefixTree/StartPrefixTree.java Mon Feb 25 20:44:55 2019 +0900 @@ -9,29 +9,31 @@ public class StartPrefixTree extends StartCodeGear { + public StartPrefixTree(CodeGearManager cgm) { super(cgm); } - - public static void main(String[] args){ + public static void main(String[] args) { int topologyManagerPort = 10000; int topologyNodePort = 10001; - int nodeNum = 3; - - String[] managerArg = {"--localPort", String.valueOf(topologyManagerPort), "--localPort", "tree"}; + int nodeNum = 10; + String[] managerArg = {"--localPort", String.valueOf(topologyManagerPort), "--Topology", "tree"}; TopologyManagerConfig topologyManagerConfig = new TopologyManagerConfig(managerArg); new StartTopologyManager(topologyManagerConfig); - for (int i = 0; i < nodeNum; i++){ + for (int i = 0; i < nodeNum ; i++){ String[] nodeArg = { - "--managerPort", String.valueOf(topologyNodePort), + "--managerPort", String.valueOf(topologyManagerPort), "--managerHost", "localhost", - "--localPort", String.valueOf(topologyNodePort + 1)}; - TopologyNodeConfig cs = new TopologyNodeConfig(nodeArg); - new StartTopologyNode(cs, new ChildCodeGear()).put("maxNodeNum",topologyManagerConfig.hasChild); + "--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を除いた分のノード数 } } + }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/PrefixTree/sendOrDisplay.java Mon Feb 25 20:44:55 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); + } + } +}