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
|
|
20 @Peek
|
|
21 HashMap<String, HostMessage> nameTable;
|
|
22
|
|
23 @Take
|
|
24 String MD5;
|
|
25
|
|
26 @Peek
|
|
27 HashMap<String, String> absCookieTable;
|
|
28
|
|
29 @Peek
|
|
30 ParentManager parentManager;
|
|
31
|
|
32 public CreateTreeTopology(){
|
|
33 }
|
|
34
|
|
35 @Override
|
|
36 protected void run(CodeGearManager cgm) {
|
|
37 System.out.println("cookie:" + MD5);
|
|
38
|
|
39 String nodeName = "node" + hostCount;
|
|
40 // Manager connect to Node
|
|
41
|
|
42 cgm.createRemoteDGM(nodeName, newHost.hostName, newHost.port);
|
|
43
|
|
44 getDGM(nodeName).put("nodeName", nodeName);
|
|
45 getDGM(nodeName).put("cookie", MD5);
|
|
46
|
|
47 absCookieTable.put(MD5, nodeName);
|
|
48 getLocalDGM().put("hostCount", hostCount + 1);
|
|
49
|
|
50 newHost.alive = true;
|
|
51 nameTable.put(nodeName, newHost);
|
|
52 parentManager.register(nodeName);
|
|
53
|
|
54 if (hostCount == 0) {
|
|
55 // どこにも繋がれるところがないので, ルートのとき.
|
|
56 // ルートなので, connectNodeNumもreverseCountも0でいい.
|
|
57 getDGM(nodeName).put("connectNodeNum", 0);
|
|
58 getDGM(nodeName).put("reverseCount", 0);
|
|
59 getLocalDGM().put("start", true);
|
|
60
|
|
61 } else {
|
|
62 // 親のみにつながればいいので1
|
|
63 getDGM(nodeName).put("connectNodeNum", 1);
|
|
64 // put parent information own
|
|
65 String parentNodeName = parentManager.getMyParent();
|
|
66 HostMessage parent = nameTable.get(parentNodeName);
|
|
67 int num = parentManager.getMyNumber();
|
|
68
|
|
69 HostMessage newHost = new HostMessage(parent.hostName, parent.port, "parent", "child" + num);
|
|
70 newHost.nodeName = parentNodeName;
|
|
71 newHost.remoteNodeName = nodeName; // address
|
|
72
|
|
73 getLocalDGM().put("nodeInfo", newHost);
|
|
74 cgm.setup(new RecordTopology());
|
|
75
|
|
76 // put own information parent
|
|
77 newHost = new HostMessage(newHost.hostName, newHost.port, "child" + num, "parent");
|
|
78 newHost.nodeName = nodeName;
|
|
79 newHost.remoteNodeName = parentNodeName;
|
|
80
|
|
81 getLocalDGM().put("nodeInfo", newHost);
|
|
82 cgm.setup(new RecordTopology());
|
|
83 }
|
|
84 }
|
|
85 } |