Mercurial > hg > Database > Christie
changeset 205:87e9abce774f
add PrefixTree
author | ichikitakahiro <e165713@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 11 Mar 2019 00:20:53 +0900 |
parents | dd3c0ba6a0a6 (current diff) 8ba56d64865f (diff) |
children | 7beaa2839c3c |
files | |
diffstat | 10 files changed, 266 insertions(+), 0 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 Mar 11 00:20:53 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); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/PrefixTree/CheckMyName.java Mon Mar 11 00:20:53 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 Mar 11 00:20:53 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()); + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/PrefixTree/CountCalculate.java Mon Mar 11 00:20:53 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.Message; +import christie.topology.TopologyDataGear; + +public class CountCalculate extends CodeGear { + @Peek + TopologyDataGear topoDG; + + @Override + protected void run(CodeGearManager cgm) { + int childNum = topoDG.getConnectionList().size(); + 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/test/java/christie/example/PrefixTree/CountMessage.java Mon Mar 11 00:20:53 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()); + System.out.println(nodeName); + } + + cgm.setup(new CountCalculate()); + }else{ + cgm.setup(new CountMessage()); + put("count",count); + } + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/PrefixTree/ReceiveMessage.java Mon Mar 11 00:20:53 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/RelayStart.java Mon Mar 11 00:20:53 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()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/PrefixTree/Root.java Mon Mar 11 00:20:53 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()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/PrefixTree/StartPrefixTree.java Mon Mar 11 00:20:53 2019 +0900 @@ -0,0 +1,39 @@ +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); + + 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を除いた分のノード数 + } + + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/christie/example/PrefixTree/sendOrDisplay.java Mon Mar 11 00:20:53 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); + } + } +}