Mercurial > hg > Database > Alice
annotate src/main/java/alice/topology/fix/FixTopology.java @ 492:24e535123df7 dispose
add PrepareToClose CodeSegment
author | sugi |
---|---|
date | Thu, 11 Dec 2014 06:29:31 +0900 (2014-12-10) |
parents | 9a7dd7591ddc |
children | f82f259ea93b |
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 | |
18 private Receiver info2 = ids.create(CommandType.TAKE); // node count | |
476 | 19 private Receiver info3 = ids.create(CommandType.TAKE); // IP Table |
20 private Receiver info4 = ids.create(CommandType.TAKE); // parentManager | |
21 | |
474 | 22 public FixTopology() { |
478 | 23 info.setKey("_DISCONNECTNODE"); |
474 | 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() { | |
484 | 33 ConnectionInfo lost = info.asClass(ConnectionInfo.class); |
34 System.out.println(lost.port+" "+lost.nodeName); | |
476 | 35 HashMap<String, HostMessage> nameTable = info3.asClass(HashMap.class); |
477
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
36 ParentManager manager = info4.asClass(ParentManager.class); |
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
37 HashMap<String, LinkedList<HostMessage>> topology = info1.asClass(HashMap.class); |
484 | 38 HostMessage lostNode = null; |
39 String lostNodeName = null; | |
482 | 40 for (String name : nameTable.keySet()) { |
484 | 41 lostNode = nameTable.get(name); |
42 if ((lostNode.name.equals(lost.addr)||lostNode.name.equals(lost.hostname)) | |
43 && lostNode.port == lost.port) { | |
44 lostNodeName = name; | |
482 | 45 break; |
46 } | |
484 | 47 lostNode = null; |
482 | 48 } |
477
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
49 |
484 | 50 if (lostNode!=null && lostNode.isAlive()) { |
476 | 51 // change state not Alive |
484 | 52 lostNode.alive = false; |
476 | 53 // get lastJoinedNode |
54 int last = info2.asInteger()-1; | |
482 | 55 String lastJoinNodeName = "node"+last; |
56 LinkedList<HostMessage> connectionList = topology.get(lastJoinNodeName); | |
477
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
57 // lastJoinedNode has one connection |
482 | 58 HostMessage parentNode = connectionList.poll(); |
492 | 59 Parent p = manager.find(parentNode.absName); |
60 p.decrement(); | |
474 | 61 |
482 | 62 connectionList = topology.get(parentNode.absName); |
63 for (HostMessage node1 : connectionList) { | |
64 if (node1.absName.equals(lastJoinNodeName)) { | |
65 connectionList.remove(node1); | |
477
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
66 break; |
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
67 } |
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
68 } |
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
69 |
484 | 70 if (!lastJoinNodeName.equals(lostNodeName)) { |
489 | 71 if (!lostNodeName.equals(parentNode.remoteAbsName)) { |
484 | 72 // send close message to lastJoinedNode |
73 ods.put(lastJoinNodeName, "_CLOSEMESSEAGE", parentNode.reverseName); | |
74 // send close message to lastJoinedNode's parent | |
75 ods.put(parentNode.absName, "_CLOSEMESSEAGE", parentNode.connectionName); | |
76 } | |
474 | 77 |
482 | 78 HostMessage lastJoinNode = nameTable.get(lastJoinNodeName); |
79 connectionList = topology.get(lastJoinNodeName); | |
484 | 80 LinkedList<HostMessage> disconnectionList = topology.get(lostNodeName); |
476 | 81 // remove NodeInformation from disconnection node's children and parent |
82 for (HostMessage node :disconnectionList) { | |
83 LinkedList<HostMessage> list = topology.get(node.absName); | |
484 | 84 if (!node.absName.equals(lastJoinNodeName)) { |
85 for (HostMessage node1 : list) { | |
86 if (node1.absName.equals(lostNodeName)) { | |
87 node1.name = lastJoinNode.name; | |
88 node1.port = lastJoinNode.port; | |
89 node1.absName = lastJoinNodeName; | |
90 ods.put(node1.remoteAbsName, node1); | |
492 | 91 p = manager.find(lastJoinNodeName); |
92 p.increment(); | |
484 | 93 break; |
94 } | |
95 } | |
96 node.remoteAbsName = lastJoinNodeName; | |
97 ods.put(node.remoteAbsName, node); | |
98 connectionList.add(node); | |
99 } else { | |
100 for (HostMessage node1 :disconnectionList) { | |
101 if ("parent".equals(node1.connectionName)) { | |
102 node1.reverseName = lastJoinNodeName; | |
103 list.add(node1); | |
104 ods.put(node1.remoteAbsName, node1); | |
105 break; | |
106 } | |
474 | 107 } |
489 | 108 |
474 | 109 } |
110 } | |
482 | 111 disconnectionList.clear(); |
484 | 112 manager.replaceAndRemove(lostNodeName, lastJoinNodeName); |
474 | 113 } else { |
476 | 114 // disconnection node is lastJoinedNode |
484 | 115 manager.remove(lostNodeName); |
474 | 116 } |
489 | 117 |
118 // need debug option | |
119 for (LinkedList<HostMessage> list :topology.values()){ | |
120 if (list.size() !=0) { | |
121 System.out.print(list.get(0).remoteAbsName+" : "); | |
122 for (HostMessage host : list){ | |
123 System.out.print("[ "+host.absName+" "+host.name+" "+host.port+" "+host.connectionName+" "+host.reverseName+" "+host.remoteAbsName+" ]"); | |
124 } | |
125 System.out.println(); | |
126 } | |
127 } | |
128 | |
129 manager.show(); | |
474 | 130 } else { |
476 | 131 // disconnect message already received. |
474 | 132 } |
478 | 133 |
477
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
134 ods.put(info1.key, topology); |
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
135 ods.put(info2.key, info2.getReceiveData()); |
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
136 ods.put(info3.key, nameTable); |
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
137 ods.put(info4.key, manager); |
474 | 138 } |
139 } |