annotate src/main/java/alice/topology/fix/FixTopology.java @ 496:f82f259ea93b dispose

putConnectionInfo only called from keepAlive deamon
author sugi
date Fri, 12 Dec 2014 05:29:31 +0900
parents 24e535123df7
children 5adb0f530e3d
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;
489
9a7dd7591ddc bug fix
sugi
parents: 484
diff changeset
11 import alice.topology.manager.Parent;
476
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
12 import alice.topology.manager.ParentManager;
474
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
13
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
14 public class FixTopology extends CodeSegment {
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
15
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
16 private Receiver info = ids.create(CommandType.TAKE); // disconnection nodeInfo
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
17 private Receiver info1 = ids.create(CommandType.TAKE); // all connection Info
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() {
478
cf345b10a21a bug fix
sugi
parents: 477
diff changeset
22 info.setKey("_DISCONNECTNODE");
474
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
23 info1.setKey("topology");
476
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
24 info3.setKey("nameTable");
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
25 info4.setKey("parentManager");
474
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
26 }
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
27
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
28 @SuppressWarnings("unchecked")
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
29 @Override
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
30 public void run() {
484
sugi
parents: 482
diff changeset
31 ConnectionInfo lost = info.asClass(ConnectionInfo.class);
sugi
parents: 482
diff changeset
32 System.out.println(lost.port+" "+lost.nodeName);
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);
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
sugi
parents: 482
diff changeset
36 HostMessage lostNode = null;
sugi
parents: 482
diff changeset
37 String lostNodeName = null;
482
8227a2fd5a55 bug fix
sugi
parents: 478
diff changeset
38 for (String name : nameTable.keySet()) {
484
sugi
parents: 482
diff changeset
39 lostNode = nameTable.get(name);
sugi
parents: 482
diff changeset
40 if ((lostNode.name.equals(lost.addr)||lostNode.name.equals(lost.hostname))
sugi
parents: 482
diff changeset
41 && lostNode.port == lost.port) {
sugi
parents: 482
diff changeset
42 lostNodeName = name;
482
8227a2fd5a55 bug fix
sugi
parents: 478
diff changeset
43 break;
8227a2fd5a55 bug fix
sugi
parents: 478
diff changeset
44 }
484
sugi
parents: 482
diff changeset
45 lostNode = null;
482
8227a2fd5a55 bug fix
sugi
parents: 478
diff changeset
46 }
477
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
47
484
sugi
parents: 482
diff changeset
48 if (lostNode!=null && lostNode.isAlive()) {
476
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
49 // change state not Alive
484
sugi
parents: 482
diff changeset
50 lostNode.alive = false;
476
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
51 // get lastJoinedNode
496
f82f259ea93b putConnectionInfo only called from keepAlive deamon
sugi
parents: 492
diff changeset
52 String lastJoinNodeName = manager.getLastNode().getName();
482
8227a2fd5a55 bug fix
sugi
parents: 478
diff changeset
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
8227a2fd5a55 bug fix
sugi
parents: 478
diff changeset
55 HostMessage parentNode = connectionList.poll();
492
24e535123df7 add PrepareToClose CodeSegment
sugi
parents: 489
diff changeset
56 Parent p = manager.find(parentNode.absName);
24e535123df7 add PrepareToClose CodeSegment
sugi
parents: 489
diff changeset
57 p.decrement();
474
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
58
482
8227a2fd5a55 bug fix
sugi
parents: 478
diff changeset
59 connectionList = topology.get(parentNode.absName);
8227a2fd5a55 bug fix
sugi
parents: 478
diff changeset
60 for (HostMessage node1 : connectionList) {
8227a2fd5a55 bug fix
sugi
parents: 478
diff changeset
61 if (node1.absName.equals(lastJoinNodeName)) {
8227a2fd5a55 bug fix
sugi
parents: 478
diff changeset
62 connectionList.remove(node1);
477
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
63 break;
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
64 }
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
65 }
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
66
484
sugi
parents: 482
diff changeset
67 if (!lastJoinNodeName.equals(lostNodeName)) {
489
9a7dd7591ddc bug fix
sugi
parents: 484
diff changeset
68 if (!lostNodeName.equals(parentNode.remoteAbsName)) {
484
sugi
parents: 482
diff changeset
69 // send close message to lastJoinedNode
sugi
parents: 482
diff changeset
70 ods.put(lastJoinNodeName, "_CLOSEMESSEAGE", parentNode.reverseName);
sugi
parents: 482
diff changeset
71 // send close message to lastJoinedNode's parent
sugi
parents: 482
diff changeset
72 ods.put(parentNode.absName, "_CLOSEMESSEAGE", parentNode.connectionName);
sugi
parents: 482
diff changeset
73 }
474
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
74
482
8227a2fd5a55 bug fix
sugi
parents: 478
diff changeset
75 HostMessage lastJoinNode = nameTable.get(lastJoinNodeName);
8227a2fd5a55 bug fix
sugi
parents: 478
diff changeset
76 connectionList = topology.get(lastJoinNodeName);
484
sugi
parents: 482
diff changeset
77 LinkedList<HostMessage> disconnectionList = topology.get(lostNodeName);
476
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
78 // remove NodeInformation from disconnection node's children and parent
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
79 for (HostMessage node :disconnectionList) {
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
80 LinkedList<HostMessage> list = topology.get(node.absName);
484
sugi
parents: 482
diff changeset
81 if (!node.absName.equals(lastJoinNodeName)) {
sugi
parents: 482
diff changeset
82 for (HostMessage node1 : list) {
sugi
parents: 482
diff changeset
83 if (node1.absName.equals(lostNodeName)) {
sugi
parents: 482
diff changeset
84 node1.name = lastJoinNode.name;
sugi
parents: 482
diff changeset
85 node1.port = lastJoinNode.port;
sugi
parents: 482
diff changeset
86 node1.absName = lastJoinNodeName;
sugi
parents: 482
diff changeset
87 ods.put(node1.remoteAbsName, node1);
492
24e535123df7 add PrepareToClose CodeSegment
sugi
parents: 489
diff changeset
88 p = manager.find(lastJoinNodeName);
24e535123df7 add PrepareToClose CodeSegment
sugi
parents: 489
diff changeset
89 p.increment();
484
sugi
parents: 482
diff changeset
90 break;
sugi
parents: 482
diff changeset
91 }
sugi
parents: 482
diff changeset
92 }
sugi
parents: 482
diff changeset
93 node.remoteAbsName = lastJoinNodeName;
sugi
parents: 482
diff changeset
94 ods.put(node.remoteAbsName, node);
sugi
parents: 482
diff changeset
95 connectionList.add(node);
sugi
parents: 482
diff changeset
96 } else {
sugi
parents: 482
diff changeset
97 for (HostMessage node1 :disconnectionList) {
sugi
parents: 482
diff changeset
98 if ("parent".equals(node1.connectionName)) {
sugi
parents: 482
diff changeset
99 node1.reverseName = lastJoinNodeName;
sugi
parents: 482
diff changeset
100 list.add(node1);
sugi
parents: 482
diff changeset
101 ods.put(node1.remoteAbsName, node1);
sugi
parents: 482
diff changeset
102 break;
sugi
parents: 482
diff changeset
103 }
474
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
104 }
489
9a7dd7591ddc bug fix
sugi
parents: 484
diff changeset
105
474
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
106 }
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
107 }
482
8227a2fd5a55 bug fix
sugi
parents: 478
diff changeset
108 disconnectionList.clear();
484
sugi
parents: 482
diff changeset
109 manager.replaceAndRemove(lostNodeName, lastJoinNodeName);
474
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
110 } else {
476
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
111 // disconnection node is lastJoinedNode
484
sugi
parents: 482
diff changeset
112 manager.remove(lostNodeName);
474
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
113 }
489
9a7dd7591ddc bug fix
sugi
parents: 484
diff changeset
114
9a7dd7591ddc bug fix
sugi
parents: 484
diff changeset
115 // need debug option
9a7dd7591ddc bug fix
sugi
parents: 484
diff changeset
116 for (LinkedList<HostMessage> list :topology.values()){
9a7dd7591ddc bug fix
sugi
parents: 484
diff changeset
117 if (list.size() !=0) {
9a7dd7591ddc bug fix
sugi
parents: 484
diff changeset
118 System.out.print(list.get(0).remoteAbsName+" : ");
9a7dd7591ddc bug fix
sugi
parents: 484
diff changeset
119 for (HostMessage host : list){
9a7dd7591ddc bug fix
sugi
parents: 484
diff changeset
120 System.out.print("[ "+host.absName+" "+host.name+" "+host.port+" "+host.connectionName+" "+host.reverseName+" "+host.remoteAbsName+" ]");
9a7dd7591ddc bug fix
sugi
parents: 484
diff changeset
121 }
9a7dd7591ddc bug fix
sugi
parents: 484
diff changeset
122 System.out.println();
9a7dd7591ddc bug fix
sugi
parents: 484
diff changeset
123 }
9a7dd7591ddc bug fix
sugi
parents: 484
diff changeset
124 }
9a7dd7591ddc bug fix
sugi
parents: 484
diff changeset
125
9a7dd7591ddc bug fix
sugi
parents: 484
diff changeset
126 manager.show();
474
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
127 } else {
476
8968b24c1ce3 TODO is to fix ParentManager information
sugi
parents: 474
diff changeset
128 // disconnect message already received.
474
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
129 }
478
cf345b10a21a bug fix
sugi
parents: 477
diff changeset
130
477
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
131 ods.put(info1.key, topology);
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
132 ods.put(info3.key, nameTable);
f644dc9e0589 TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents: 476
diff changeset
133 ods.put(info4.key, manager);
474
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
134 }
6a71732cd3ee add topology fix package
sugi
parents:
diff changeset
135 }