Mercurial > hg > Database > Alice
annotate src/main/java/alice/topology/fix/FixTopology.java @ 482:8227a2fd5a55 dispose
bug fix
author | sugi |
---|---|
date | Fri, 05 Dec 2014 17:22:33 +0900 |
parents | cf345b10a21a |
children | c00437e91db0 |
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; | |
476 | 11 import alice.topology.manager.ParentManager; |
474 | 12 |
13 public class FixTopology extends CodeSegment { | |
14 | |
15 private Receiver info = ids.create(CommandType.TAKE); // disconnection nodeInfo | |
16 private Receiver info1 = ids.create(CommandType.TAKE); // all connection Info | |
17 private Receiver info2 = ids.create(CommandType.TAKE); // node count | |
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"); |
24 info2.setKey("hostCount"); | |
476 | 25 info3.setKey("nameTable"); |
26 info4.setKey("parentManager"); | |
474 | 27 } |
28 | |
29 @SuppressWarnings("unchecked") | |
30 @Override | |
31 public void run() { | |
482 | 32 ConnectionInfo disconnect = info.asClass(ConnectionInfo.class); |
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); |
482 | 36 HostMessage disconnectNode = null; |
37 String disconnectNodeName = null; | |
38 for (String name : nameTable.keySet()) { | |
39 disconnectNode = nameTable.get(name); | |
40 if ((disconnectNode.name.equals(disconnect.addr)||disconnectNode.name.equals(disconnect.hostname)) | |
41 && disconnectNode.port == disconnect.port) { | |
42 disconnectNodeName = name; | |
43 break; | |
44 } | |
45 disconnectNode = null; | |
46 } | |
477
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
47 |
482 | 48 if (disconnectNode!=null && disconnectNode.isAlive()) { |
476 | 49 // change state not Alive |
50 disconnectNode.alive = false; | |
51 // get lastJoinedNode | |
52 int last = info2.asInteger()-1; | |
482 | 53 String lastJoinNodeName = "node"+last; |
54 LinkedList<HostMessage> connectionList = topology.get(lastJoinNodeName); | |
477
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
55 // lastJoinedNode has one connection |
482 | 56 HostMessage parentNode = connectionList.poll(); |
474 | 57 |
482 | 58 connectionList = topology.get(parentNode.absName); |
59 for (HostMessage node1 : connectionList) { | |
60 if (node1.absName.equals(lastJoinNodeName)) { | |
61 connectionList.remove(node1); | |
477
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
62 break; |
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
63 } |
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 |
482 | 66 if (!lastJoinNodeName.equals(disconnectNodeName)) { |
476 | 67 // send close message to lastJoinedNode |
482 | 68 ods.put(lastJoinNodeName, "_CLOSEMESSEAGE", parentNode.reverseName); |
476 | 69 // send close message to lastJoinedNode's parent |
482 | 70 ods.put(parentNode.absName, "_CLOSEMESSEAGE", parentNode.connectionName); |
474 | 71 |
482 | 72 HostMessage lastJoinNode = nameTable.get(lastJoinNodeName); |
73 connectionList = topology.get(lastJoinNodeName); | |
74 LinkedList<HostMessage> disconnectionList = topology.get(disconnectNodeName); | |
476 | 75 // remove NodeInformation from disconnection node's children and parent |
76 for (HostMessage node :disconnectionList) { | |
77 LinkedList<HostMessage> list = topology.get(node.absName); | |
78 for (HostMessage node1 : list) { | |
482 | 79 if (node1.absName.equals(disconnectNodeName)) { |
80 node1.name = lastJoinNode.name; | |
81 node1.port = lastJoinNode.port; | |
82 node1.absName = lastJoinNodeName; | |
83 ods.put(node1.remoteAbsName, node1); | |
474 | 84 break; |
85 } | |
86 } | |
482 | 87 node.remoteAbsName = lastJoinNodeName; |
88 ods.put(node.remoteAbsName, node); | |
476 | 89 connectionList.add(node); |
474 | 90 } |
482 | 91 disconnectionList.clear(); |
92 manager.replaceAndRemove(disconnectNodeName, lastJoinNodeName); | |
474 | 93 } else { |
476 | 94 // disconnection node is lastJoinedNode |
482 | 95 manager.remove(disconnectNodeName); |
474 | 96 } |
97 } else { | |
476 | 98 // disconnect message already received. |
474 | 99 } |
478 | 100 |
101 // need debug option | |
102 for (LinkedList<HostMessage> list :topology.values()){ | |
482 | 103 if (list.size() !=0) { |
104 System.out.print(list.get(0).remoteAbsName+" : "); | |
105 for (HostMessage host : list){ | |
106 System.out.print("[ "+host.absName+" "+host.name+" "+host.port+" "+host.connectionName+" "+host.reverseName+" "+host.remoteAbsName+" ]"); | |
107 } | |
108 System.out.println(); | |
478 | 109 } |
110 } | |
482 | 111 |
477
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
112 ods.put(info1.key, topology); |
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
113 ods.put(info2.key, info2.getReceiveData()); |
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
114 ods.put(info3.key, nameTable); |
f644dc9e0589
TODO : add ReceiveCloseOrder CodeSegment in alice.topology.node package
sugi
parents:
476
diff
changeset
|
115 ods.put(info4.key, manager); |
474 | 116 } |
117 } |