Mercurial > hg > Database > Alice
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 |
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() { |
22 info.setKey("_DISCONNECT"); | |
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() { | |
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); |
476 | 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 | 38 if (disconnectNode.isAlive()) { |
39 // change state not Alive | |
40 disconnectNode.alive = false; | |
41 // get lastJoinedNode | |
42 int last = info2.asInteger()-1; | |
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 | 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 | 56 // send close message to lastJoinedNode |
57 ods.put(lastJoinedNode, "_CLOSEMESSEAGE", parentInfo.reverseName); | |
58 // send close message to lastJoinedNode's parent | |
59 ods.put(parentInfo.absName, "_CLOSEMESSEAGE", parentInfo.connectionName); | |
474 | 60 |
476 | 61 HostMessage lastJoined = nameTable.get(lastJoinedNode); |
62 LinkedList<HostMessage> disconnectionList = topology.get(disconnect.nodeName); | |
63 // remove NodeInformation from disconnection node's children and parent | |
64 for (HostMessage node :disconnectionList) { | |
65 LinkedList<HostMessage> list = topology.get(node.absName); | |
66 for (HostMessage node1 : list) { | |
67 if (node1.absName.equals(disconnect.nodeName)) { | |
68 node1.name = lastJoined.name; | |
69 node1.port = lastJoined.port; | |
70 node1.absName = lastJoinedNode; | |
474 | 71 break; |
72 } | |
476 | 73 ods.put(node1.remoteAbsName, node1); |
474 | 74 } |
476 | 75 node.absName = lastJoinedNode; |
76 ods.put(lastJoinedNode, node); | |
77 connectionList.add(node); | |
474 | 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 | 81 } else { |
476 | 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 | 84 } |
85 } else { | |
476 | 86 // disconnect message already received. |
474 | 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 | 92 } |
93 } |