annotate src/main/java/alice/topology/fix/FixTopology.java @ 476:8968b24c1ce3 dispose

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