Mercurial > hg > Database > Alice
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 |
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(); |
492 | 56 Parent p = manager.find(parentNode.absName); |
57 p.decrement(); | |
474 | 58 |
482 | 59 connectionList = topology.get(parentNode.absName); |
60 for (HostMessage node1 : connectionList) { | |
61 if (node1.absName.equals(lastJoinNodeName)) { | |
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 | 67 if (!lastJoinNodeName.equals(lostNodeName)) { |
489 | 68 if (!lostNodeName.equals(parentNode.remoteAbsName)) { |
484 | 69 // send close message to lastJoinedNode |
70 ods.put(lastJoinNodeName, "_CLOSEMESSEAGE", parentNode.reverseName); | |
71 // send close message to lastJoinedNode's parent | |
72 ods.put(parentNode.absName, "_CLOSEMESSEAGE", parentNode.connectionName); | |
73 } | |
474 | 74 |
482 | 75 HostMessage lastJoinNode = nameTable.get(lastJoinNodeName); |
76 connectionList = topology.get(lastJoinNodeName); | |
484 | 77 LinkedList<HostMessage> disconnectionList = topology.get(lostNodeName); |
476 | 78 // remove NodeInformation from disconnection node's children and parent |
79 for (HostMessage node :disconnectionList) { | |
80 LinkedList<HostMessage> list = topology.get(node.absName); | |
484 | 81 if (!node.absName.equals(lastJoinNodeName)) { |
82 for (HostMessage node1 : list) { | |
83 if (node1.absName.equals(lostNodeName)) { | |
84 node1.name = lastJoinNode.name; | |
85 node1.port = lastJoinNode.port; | |
86 node1.absName = lastJoinNodeName; | |
87 ods.put(node1.remoteAbsName, node1); | |
492 | 88 p = manager.find(lastJoinNodeName); |
89 p.increment(); | |
484 | 90 break; |
91 } | |
92 } | |
93 node.remoteAbsName = lastJoinNodeName; | |
94 ods.put(node.remoteAbsName, node); | |
95 connectionList.add(node); | |
96 } else { | |
97 for (HostMessage node1 :disconnectionList) { | |
98 if ("parent".equals(node1.connectionName)) { | |
99 node1.reverseName = lastJoinNodeName; | |
100 list.add(node1); | |
101 ods.put(node1.remoteAbsName, node1); | |
102 break; | |
103 } | |
474 | 104 } |
489 | 105 |
474 | 106 } |
107 } | |
482 | 108 disconnectionList.clear(); |
484 | 109 manager.replaceAndRemove(lostNodeName, lastJoinNodeName); |
474 | 110 } else { |
476 | 111 // disconnection node is lastJoinedNode |
484 | 112 manager.remove(lostNodeName); |
474 | 113 } |
489 | 114 |
115 // need debug option | |
116 for (LinkedList<HostMessage> list :topology.values()){ | |
117 if (list.size() !=0) { | |
118 System.out.print(list.get(0).remoteAbsName+" : "); | |
119 for (HostMessage host : list){ | |
120 System.out.print("[ "+host.absName+" "+host.name+" "+host.port+" "+host.connectionName+" "+host.reverseName+" "+host.remoteAbsName+" ]"); | |
121 } | |
122 System.out.println(); | |
123 } | |
124 } | |
125 | |
126 manager.show(); | |
474 | 127 } else { |
476 | 128 // disconnect message already received. |
474 | 129 } |
478 | 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 | 134 } |
135 } |