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