83
|
1 package christie.topology.manager;
|
|
2
|
|
3
|
|
4 import christie.annotation.Peek;
|
|
5 import christie.annotation.Take;
|
|
6 import christie.codegear.CodeGear;
|
|
7 import christie.codegear.CodeGearManager;
|
|
8 import christie.topology.HostMessage;
|
|
9
|
|
10 import java.util.HashMap;
|
|
11
|
|
12 public class CreateTreeTopology extends CodeGear{
|
|
13
|
|
14 @Take
|
|
15 HostMessage newHost;
|
|
16
|
|
17 @Take
|
|
18 int hostCount;
|
|
19
|
129
|
20 @Take
|
83
|
21 HashMap<String, HostMessage> nameTable;
|
|
22
|
|
23 @Take
|
|
24 String MD5;
|
|
25
|
129
|
26 @Take
|
83
|
27 HashMap<String, String> absCookieTable;
|
|
28
|
129
|
29 @Take
|
83
|
30 ParentManager parentManager;
|
|
31
|
|
32 public CreateTreeTopology(){
|
|
33 }
|
|
34
|
|
35 @Override
|
|
36 protected void run(CodeGearManager cgm) {
|
95
|
37
|
83
|
38
|
|
39 String nodeName = "node" + hostCount;
|
94
|
40 String newHostName = newHost.getHostName();
|
|
41 int newHostPort = newHost.getPort();
|
|
42
|
95
|
43
|
94
|
44 cgm.createRemoteDGM(nodeName, newHostName, newHostPort);
|
83
|
45 getDGM(nodeName).put("nodeName", nodeName);
|
|
46 getDGM(nodeName).put("cookie", MD5);
|
|
47
|
|
48 absCookieTable.put(MD5, nodeName);
|
129
|
49 getLocalDGM().put("absCookieTable", absCookieTable);
|
|
50
|
83
|
51 getLocalDGM().put("hostCount", hostCount + 1);
|
94
|
52 newHost.setAlive(true);
|
83
|
53 nameTable.put(nodeName, newHost);
|
|
54 parentManager.register(nodeName);
|
|
55
|
|
56 if (hostCount == 0) {
|
|
57 // どこにも繋がれるところがないので, ルートのとき.
|
|
58 // ルートなので, connectNodeNumもreverseCountも0でいい.
|
|
59 getDGM(nodeName).put("connectNodeNum", 0);
|
|
60 getDGM(nodeName).put("reverseCount", 0);
|
|
61
|
|
62 } else {
|
|
63 // 親のみにつながればいいので1
|
|
64 getDGM(nodeName).put("connectNodeNum", 1);
|
|
65 // put parent information own
|
|
66 String parentNodeName = parentManager.getMyParent();
|
129
|
67 HostMessage parentHost = nameTable.get(parentNodeName).clone();
|
|
68
|
83
|
69
|
94
|
70 // 相手からhostNameとportはもらっているので, nodeの情報だけ与えれば良い.
|
114
|
71 parentHost.setNodeInfo(nodeName, "parent", parentNodeName);
|
129
|
72 //parentHost.setNodeInfo(parentNodeName, "child", nodeName);
|
94
|
73 getLocalDGM().put("nodeInfo", parentHost);
|
83
|
74 cgm.setup(new RecordTopology());
|
|
75
|
94
|
76 // newChildHost, newHostも同じ
|
114
|
77 newHost.setNodeInfo(parentNodeName, "child" + parentManager.getMyNumber(), nodeName);
|
94
|
78 getLocalDGM().put("nodeInfo", newHost);
|
83
|
79 cgm.setup(new RecordTopology());
|
|
80 }
|
85
|
81
|
129
|
82 getLocalDGM().put("nameTable", nameTable);
|
|
83 getLocalDGM().put("parentManager", parentManager);
|
|
84
|
85
|
85 getDGM(nodeName).put("start", "start");
|
100
|
86 getLocalDGM().put("startTime", System.currentTimeMillis());
|
85
|
87
|
92
|
88 cgm.setup(new CreateTreeTopology());
|
83
|
89 }
|
|
90 } |