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;
|
476
|
11 import alice.topology.manager.ParentManager;
|
474
|
12
|
|
13 public class FixTopology extends CodeSegment {
|
|
14
|
|
15 private Receiver info = ids.create(CommandType.TAKE); // disconnection nodeInfo
|
|
16 private Receiver info1 = ids.create(CommandType.TAKE); // all connection Info
|
|
17 private Receiver info2 = ids.create(CommandType.TAKE); // node count
|
476
|
18 private Receiver info3 = ids.create(CommandType.TAKE); // IP Table
|
|
19 private Receiver info4 = ids.create(CommandType.TAKE); // parentManager
|
|
20
|
474
|
21
|
|
22 public FixTopology() {
|
|
23 info.setKey("_DISCONNECT");
|
|
24 info1.setKey("topology");
|
|
25 info2.setKey("hostCount");
|
476
|
26 info3.setKey("nameTable");
|
|
27 info4.setKey("parentManager");
|
474
|
28 }
|
|
29
|
|
30 @SuppressWarnings("unchecked")
|
|
31 @Override
|
|
32 public void run() {
|
|
33 ConnectionInfo disconnect = info.asClass(ConnectionInfo.class);
|
476
|
34 HashMap<String, HostMessage> nameTable = info3.asClass(HashMap.class);
|
|
35 HostMessage disconnectNode = nameTable.get(disconnect.nodeName);
|
|
36 if (disconnectNode.isAlive()) {
|
|
37 // change state not Alive
|
|
38 disconnectNode.alive = false;
|
|
39 // get lastJoinedNode
|
|
40 int last = info2.asInteger()-1;
|
|
41 String lastJoinedNode = "node"+last;
|
|
42 if (!lastJoinedNode.equals(disconnect.nodeName)) {
|
|
43 HashMap<String, LinkedList<HostMessage>> topology = info1.asClass(HashMap.class);
|
474
|
44
|
476
|
45 LinkedList<HostMessage> connectionList = topology.get(lastJoinedNode);
|
|
46 // lastJoinedNode has one connection
|
|
47 HostMessage parentInfo = connectionList.poll();
|
|
48 // send close message to lastJoinedNode
|
|
49 ods.put(lastJoinedNode, "_CLOSEMESSEAGE", parentInfo.reverseName);
|
474
|
50
|
476
|
51 // send close message to lastJoinedNode's parent
|
|
52 ods.put(parentInfo.absName, "_CLOSEMESSEAGE", parentInfo.connectionName);
|
|
53 for (HostMessage node1 : topology.get(parentInfo.absName)) {
|
|
54 if (node1.remoteAbsName.equals(lastJoinedNode)) {
|
|
55 list.remove(node1);
|
|
56 break;
|
|
57 }
|
|
58 }
|
474
|
59
|
476
|
60 HostMessage lastJoined = nameTable.get(lastJoinedNode);
|
|
61 LinkedList<HostMessage> disconnectionList = topology.get(disconnect.nodeName);
|
|
62 // remove NodeInformation from disconnection node's children and parent
|
|
63 for (HostMessage node :disconnectionList) {
|
|
64 LinkedList<HostMessage> list = topology.get(node.absName);
|
|
65 for (HostMessage node1 : list) {
|
|
66 if (node1.absName.equals(disconnect.nodeName)) {
|
|
67 node1.name = lastJoined.name;
|
|
68 node1.port = lastJoined.port;
|
|
69 node1.absName = lastJoinedNode;
|
474
|
70 break;
|
|
71 }
|
476
|
72 ods.put(node1.remoteAbsName, node1);
|
474
|
73 }
|
476
|
74 node.absName = lastJoinedNode;
|
|
75 ods.put(lastJoinedNode, node);
|
|
76 connectionList.add(node);
|
474
|
77 }
|
|
78 } else {
|
476
|
79 // disconnection node is lastJoinedNode
|
474
|
80 }
|
|
81 } else {
|
476
|
82 // disconnect message already received.
|
474
|
83 }
|
|
84 }
|
|
85 }
|