Mercurial > hg > Database > Alice
annotate src/main/java/alice/topology/fix/FixTopology.java @ 655:1c93e82e05c6 default tip
fix timestamp
author | suruga |
---|---|
date | Sat, 17 Feb 2018 00:33:00 +0900 |
parents | 145c425db88d |
children | 15eeb439830c 767d93626b88 |
rev | line source |
---|---|
474 | 1 package alice.topology.fix; |
2 | |
3 import java.util.HashMap; | |
4 import java.util.LinkedList; | |
5 | |
6 import alice.codesegment.CodeSegment; | |
7 import alice.daemon.ConnectionInfo; | |
8 import alice.datasegment.CommandType; | |
9 import alice.datasegment.Receiver; | |
10 import alice.topology.HostMessage; | |
489 | 11 import alice.topology.manager.Parent; |
476 | 12 import alice.topology.manager.ParentManager; |
474 | 13 |
14 public class FixTopology extends CodeSegment { | |
15 | |
16 private Receiver info = ids.create(CommandType.TAKE); // disconnection nodeInfo | |
17 private Receiver info1 = ids.create(CommandType.TAKE); // all connection Info | |
476 | 18 private Receiver info3 = ids.create(CommandType.TAKE); // IP Table |
19 private Receiver info4 = ids.create(CommandType.TAKE); // parentManager | |
20 | |
474 | 21 public FixTopology() { |
478 | 22 info.setKey("_DISCONNECTNODE"); |
474 | 23 info1.setKey("topology"); |
476 | 24 info3.setKey("nameTable"); |
25 info4.setKey("parentManager"); | |
474 | 26 } |
27 | |
28 @SuppressWarnings("unchecked") | |
29 @Override | |
30 public void run() { | |
484 | 31 ConnectionInfo lost = info.asClass(ConnectionInfo.class); |
32 System.out.println(lost.port+" "+lost.nodeName); | |
476 | 33 HashMap<String, HostMessage> nameTable = info3.asClass(HashMap.class); |
477
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
34 ParentManager manager = info4.asClass(ParentManager.class); |
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
35 HashMap<String, LinkedList<HostMessage>> topology = info1.asClass(HashMap.class); |
484 | 36 HostMessage lostNode = null; |
37 String lostNodeName = null; | |
482 | 38 for (String name : nameTable.keySet()) { |
484 | 39 lostNode = nameTable.get(name); |
40 if ((lostNode.name.equals(lost.addr)||lostNode.name.equals(lost.hostname)) | |
41 && lostNode.port == lost.port) { | |
42 lostNodeName = name; | |
482 | 43 break; |
44 } | |
484 | 45 lostNode = null; |
482 | 46 } |
477
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
47 |
484 | 48 if (lostNode!=null && lostNode.isAlive()) { |
476 | 49 // change state not Alive |
484 | 50 lostNode.alive = false; |
476 | 51 // get lastJoinedNode |
496 | 52 String lastJoinNodeName = manager.getLastNode().getName(); |
482 | 53 LinkedList<HostMessage> connectionList = topology.get(lastJoinNodeName); |
477
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
54 // lastJoinedNode has one connection |
482 | 55 HostMessage parentNode = connectionList.poll(); |
474 | 56 |
482 | 57 connectionList = topology.get(parentNode.absName); |
58 for (HostMessage node1 : connectionList) { | |
59 if (node1.absName.equals(lastJoinNodeName)) { | |
60 connectionList.remove(node1); | |
477
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
61 break; |
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
62 } |
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
63 } |
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
64 |
484 | 65 if (!lastJoinNodeName.equals(lostNodeName)) { |
489 | 66 if (!lostNodeName.equals(parentNode.remoteAbsName)) { |
484 | 67 // send close message to lastJoinedNode |
502 | 68 ods.put(lastJoinNodeName, "_CLOSEMESSEAGE", parentNode.connectionName); |
484 | 69 // send close message to lastJoinedNode's parent |
502 | 70 ods.put(parentNode.absName, "_CLOSEMESSEAGE", parentNode.reverseName); |
484 | 71 } |
474 | 72 |
482 | 73 HostMessage lastJoinNode = nameTable.get(lastJoinNodeName); |
74 connectionList = topology.get(lastJoinNodeName); | |
484 | 75 LinkedList<HostMessage> disconnectionList = topology.get(lostNodeName); |
476 | 76 // remove NodeInformation from disconnection node's children and parent |
77 for (HostMessage node :disconnectionList) { | |
78 LinkedList<HostMessage> list = topology.get(node.absName); | |
484 | 79 if (!node.absName.equals(lastJoinNodeName)) { |
80 for (HostMessage node1 : list) { | |
81 if (node1.absName.equals(lostNodeName)) { | |
82 node1.name = lastJoinNode.name; | |
83 node1.port = lastJoinNode.port; | |
84 node1.absName = lastJoinNodeName; | |
85 ods.put(node1.remoteAbsName, node1); | |
86 break; | |
87 } | |
88 } | |
89 node.remoteAbsName = lastJoinNodeName; | |
90 ods.put(node.remoteAbsName, node); | |
91 connectionList.add(node); | |
92 } else { | |
93 for (HostMessage node1 :disconnectionList) { | |
94 if ("parent".equals(node1.connectionName)) { | |
95 node1.reverseName = lastJoinNodeName; | |
96 list.add(node1); | |
97 ods.put(node1.remoteAbsName, node1); | |
98 break; | |
99 } | |
474 | 100 } |
489 | 101 |
474 | 102 } |
103 } | |
482 | 104 disconnectionList.clear(); |
484 | 105 manager.replaceAndRemove(lostNodeName, lastJoinNodeName); |
474 | 106 } else { |
476 | 107 // disconnection node is lastJoinedNode |
484 | 108 manager.remove(lostNodeName); |
474 | 109 } |
489 | 110 |
497 | 111 for (Parent p1 : manager.getList()) { |
112 LinkedList<HostMessage> list = topology.get(p1.getName()); | |
113 int child = 0; | |
114 for (HostMessage h : list) { | |
115 if (!"parent".equals(h.connectionName)) { | |
116 child++; | |
117 } | |
118 } | |
119 p1.setChildren(child); | |
120 } | |
121 | |
489 | 122 // need debug option |
123 for (LinkedList<HostMessage> list :topology.values()){ | |
124 if (list.size() !=0) { | |
125 System.out.print(list.get(0).remoteAbsName+" : "); | |
126 for (HostMessage host : list){ | |
127 System.out.print("[ "+host.absName+" "+host.name+" "+host.port+" "+host.connectionName+" "+host.reverseName+" "+host.remoteAbsName+" ]"); | |
128 } | |
129 System.out.println(); | |
130 } | |
131 } | |
132 | |
133 manager.show(); | |
474 | 134 } else { |
476 | 135 // disconnect message already received. |
474 | 136 } |
478 | 137 |
477
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
138 ods.put(info1.key, topology); |
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
139 ods.put(info3.key, nameTable); |
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
140 ods.put(info4.key, manager); |
474 | 141 } |
142 } |