Mercurial > hg > Database > Christie
diff src/main/java/christie/topology/manager/CreateTreeTopology.java @ 83:2314c55534ef
add TreeTopology
author | akahori |
---|---|
date | Sat, 15 Sep 2018 09:24:36 +0900 |
parents | |
children | 331ad549e764 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/christie/topology/manager/CreateTreeTopology.java Sat Sep 15 09:24:36 2018 +0900 @@ -0,0 +1,85 @@ +package christie.topology.manager; + + +import christie.annotation.Peek; +import christie.annotation.Take; +import christie.codegear.CodeGear; +import christie.codegear.CodeGearManager; +import christie.topology.HostMessage; + +import java.util.HashMap; + +public class CreateTreeTopology extends CodeGear{ + + @Take + HostMessage newHost; + + @Take + int hostCount; + + @Peek + HashMap<String, HostMessage> nameTable; + + @Take + String MD5; + + @Peek + HashMap<String, String> absCookieTable; + + @Peek + ParentManager parentManager; + + public CreateTreeTopology(){ + } + + @Override + protected void run(CodeGearManager cgm) { + System.out.println("cookie:" + MD5); + + String nodeName = "node" + hostCount; + // Manager connect to Node + + cgm.createRemoteDGM(nodeName, newHost.hostName, newHost.port); + + getDGM(nodeName).put("nodeName", nodeName); + getDGM(nodeName).put("cookie", MD5); + + absCookieTable.put(MD5, nodeName); + getLocalDGM().put("hostCount", hostCount + 1); + + newHost.alive = true; + nameTable.put(nodeName, newHost); + parentManager.register(nodeName); + + if (hostCount == 0) { + // どこにも繋がれるところがないので, ルートのとき. + // ルートなので, connectNodeNumもreverseCountも0でいい. + getDGM(nodeName).put("connectNodeNum", 0); + getDGM(nodeName).put("reverseCount", 0); + getLocalDGM().put("start", true); + + } else { + // 親のみにつながればいいので1 + getDGM(nodeName).put("connectNodeNum", 1); + // put parent information own + String parentNodeName = parentManager.getMyParent(); + HostMessage parent = nameTable.get(parentNodeName); + int num = parentManager.getMyNumber(); + + HostMessage newHost = new HostMessage(parent.hostName, parent.port, "parent", "child" + num); + newHost.nodeName = parentNodeName; + newHost.remoteNodeName = nodeName; // address + + getLocalDGM().put("nodeInfo", newHost); + cgm.setup(new RecordTopology()); + + // put own information parent + newHost = new HostMessage(newHost.hostName, newHost.port, "child" + num, "parent"); + newHost.nodeName = nodeName; + newHost.remoteNodeName = parentNodeName; + + getLocalDGM().put("nodeInfo", newHost); + cgm.setup(new RecordTopology()); + } + } +} \ No newline at end of file