annotate src/main/java/alice/topology/fix/FixTopology.java @ 477:f644dc9e0589 dispose

TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
author sugi
date Tue, 02 Dec 2014 14:49:20 +0900
parents 8968b24c1ce3
children cf345b10a21a
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 public FixTopology() {
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
22 info.setKey("_DISCONNECT");
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
23 info1.setKey("topology");
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
24 info2.setKey("hostCount");
476
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
25 info3.setKey("nameTable");
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
26 info4.setKey("parentManager");
474
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
27 }
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
28
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
29 @SuppressWarnings("unchecked")
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
30 @Override
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
31 public void run() {
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
32 ConnectionInfo disconnect = info.asClass(ConnectionInfo.class);
476
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
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);
476
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
35 HostMessage disconnectNode = nameTable.get(disconnect.nodeName);
477
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
36 HashMap<String, LinkedList<HostMessage>> topology = info1.asClass(HashMap.class);
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
37
476
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
38 if (disconnectNode.isAlive()) {
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
39 // change state not Alive
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
40 disconnectNode.alive = false;
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
41 // get lastJoinedNode
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
42 int last = info2.asInteger()-1;
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
43 String lastJoinedNode = "node"+last;
477
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
44 LinkedList<HostMessage> connectionList = topology.get(lastJoinedNode);
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
45 // lastJoinedNode has one connection
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
46 HostMessage parentInfo = connectionList.poll();
474
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
47
477
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
48 for (HostMessage node1 : topology.get(parentInfo.absName)) {
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
49 if (node1.remoteAbsName.equals(lastJoinedNode)) {
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
50 list.remove(node1);
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
51 break;
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
52 }
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
53 }
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
54
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
55 if (!lastJoinedNode.equals(disconnect.nodeName)) {
476
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
56 // send close message to lastJoinedNode
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
57 ods.put(lastJoinedNode, "_CLOSEMESSEAGE", parentInfo.reverseName);
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
58 // send close message to lastJoinedNode's parent
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
59 ods.put(parentInfo.absName, "_CLOSEMESSEAGE", parentInfo.connectionName);
474
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
60
476
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
61 HostMessage lastJoined = nameTable.get(lastJoinedNode);
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
62 LinkedList<HostMessage> disconnectionList = topology.get(disconnect.nodeName);
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
63 // remove NodeInformation from disconnection node's children and parent
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
64 for (HostMessage node :disconnectionList) {
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
65 LinkedList<HostMessage> list = topology.get(node.absName);
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
66 for (HostMessage node1 : list) {
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
67 if (node1.absName.equals(disconnect.nodeName)) {
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
68 node1.name = lastJoined.name;
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
69 node1.port = lastJoined.port;
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
70 node1.absName = lastJoinedNode;
474
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
71 break;
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
72 }
476
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
73 ods.put(node1.remoteAbsName, node1);
474
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
74 }
476
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
75 node.absName = lastJoinedNode;
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
76 ods.put(lastJoinedNode, node);
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
77 connectionList.add(node);
474
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
78 }
477
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
79
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
80 manager.replaceAndRemove(disconnect.nodeName, lastJoinedNode);
474
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 // disconnection node is lastJoinedNode
477
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
83 manager.remove(disconnect.nodeName);
474
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
84 }
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
85 } else {
476
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
86 // disconnect message already received.
474
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
87 }
477
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
88 ods.put(info1.key, topology);
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
89 ods.put(info2.key, info2.getReceiveData());
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
90 ods.put(info3.key, nameTable);
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
91 ods.put(info4.key, manager);
474
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
92 }
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
93 }