comparison 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
comparison
equal deleted inserted replaced
481:549cc29aca59 482:8227a2fd5a55
27 } 27 }
28 28
29 @SuppressWarnings("unchecked") 29 @SuppressWarnings("unchecked")
30 @Override 30 @Override
31 public void run() { 31 public void run() {
32 ConnectionInfo disconnect = info.asClass(ConnectionInfo.class); // send Data is wrong. 32 ConnectionInfo disconnect = info.asClass(ConnectionInfo.class);
33 HashMap<String, HostMessage> nameTable = info3.asClass(HashMap.class); 33 HashMap<String, HostMessage> nameTable = info3.asClass(HashMap.class);
34 ParentManager manager = info4.asClass(ParentManager.class); 34 ParentManager manager = info4.asClass(ParentManager.class);
35 HostMessage disconnectNode = nameTable.get(disconnect.nodeName);
36 HashMap<String, LinkedList<HostMessage>> topology = info1.asClass(HashMap.class); 35 HashMap<String, LinkedList<HostMessage>> topology = info1.asClass(HashMap.class);
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 }
37 47
38 if (disconnectNode.isAlive()) { 48 if (disconnectNode!=null && disconnectNode.isAlive()) {
39 // change state not Alive 49 // change state not Alive
40 disconnectNode.alive = false; 50 disconnectNode.alive = false;
41 // get lastJoinedNode 51 // get lastJoinedNode
42 int last = info2.asInteger()-1; 52 int last = info2.asInteger()-1;
43 String lastJoinedNode = "node"+last; 53 String lastJoinNodeName = "node"+last;
44 LinkedList<HostMessage> connectionList = topology.get(lastJoinedNode); 54 LinkedList<HostMessage> connectionList = topology.get(lastJoinNodeName);
45 // lastJoinedNode has one connection 55 // lastJoinedNode has one connection
46 HostMessage parentInfo = connectionList.poll(); 56 HostMessage parentNode = connectionList.poll();
47 57
48 for (HostMessage node1 : topology.get(parentInfo.absName)) { 58 connectionList = topology.get(parentNode.absName);
49 if (node1.remoteAbsName.equals(lastJoinedNode)) { 59 for (HostMessage node1 : connectionList) {
50 list.remove(node1); 60 if (node1.absName.equals(lastJoinNodeName)) {
61 connectionList.remove(node1);
51 break; 62 break;
52 } 63 }
53 } 64 }
54 65
55 if (!lastJoinedNode.equals(disconnect.nodeName)) { 66 if (!lastJoinNodeName.equals(disconnectNodeName)) {
56 // send close message to lastJoinedNode 67 // send close message to lastJoinedNode
57 ods.put(lastJoinedNode, "_CLOSEMESSEAGE", parentInfo.reverseName); 68 ods.put(lastJoinNodeName, "_CLOSEMESSEAGE", parentNode.reverseName);
58 // send close message to lastJoinedNode's parent 69 // send close message to lastJoinedNode's parent
59 ods.put(parentInfo.absName, "_CLOSEMESSEAGE", parentInfo.connectionName); 70 ods.put(parentNode.absName, "_CLOSEMESSEAGE", parentNode.connectionName);
60 71
61 HostMessage lastJoined = nameTable.get(lastJoinedNode); 72 HostMessage lastJoinNode = nameTable.get(lastJoinNodeName);
62 LinkedList<HostMessage> disconnectionList = topology.get(disconnect.nodeName); 73 connectionList = topology.get(lastJoinNodeName);
74 LinkedList<HostMessage> disconnectionList = topology.get(disconnectNodeName);
63 // remove NodeInformation from disconnection node's children and parent 75 // remove NodeInformation from disconnection node's children and parent
64 for (HostMessage node :disconnectionList) { 76 for (HostMessage node :disconnectionList) {
65 LinkedList<HostMessage> list = topology.get(node.absName); 77 LinkedList<HostMessage> list = topology.get(node.absName);
66 for (HostMessage node1 : list) { 78 for (HostMessage node1 : list) {
67 if (node1.absName.equals(disconnect.nodeName)) { 79 if (node1.absName.equals(disconnectNodeName)) {
68 node1.name = lastJoined.name; 80 node1.name = lastJoinNode.name;
69 node1.port = lastJoined.port; 81 node1.port = lastJoinNode.port;
70 node1.absName = lastJoinedNode; 82 node1.absName = lastJoinNodeName;
83 ods.put(node1.remoteAbsName, node1);
71 break; 84 break;
72 } 85 }
73 ods.put(node1.remoteAbsName, node1);
74 } 86 }
75 node.absName = lastJoinedNode; 87 node.remoteAbsName = lastJoinNodeName;
76 ods.put(lastJoinedNode, node); 88 ods.put(node.remoteAbsName, node);
77 connectionList.add(node); 89 connectionList.add(node);
78 } 90 }
79 91 disconnectionList.clear();
80 manager.replaceAndRemove(disconnect.nodeName, lastJoinedNode); 92 manager.replaceAndRemove(disconnectNodeName, lastJoinNodeName);
81 } else { 93 } else {
82 // disconnection node is lastJoinedNode 94 // disconnection node is lastJoinedNode
83 manager.remove(disconnect.nodeName); 95 manager.remove(disconnectNodeName);
84 } 96 }
85 } else { 97 } else {
86 // disconnect message already received. 98 // disconnect message already received.
87 } 99 }
88 100
89 // need debug option 101 // need debug option
90 for (LinkedList<HostMessage> list :topology.values()){ 102 for (LinkedList<HostMessage> list :topology.values()){
91 System.out.print(list.get(0).remoteAbsName+" : "); 103 if (list.size() !=0) {
92 for (HostMessage host : list){ 104 System.out.print(list.get(0).remoteAbsName+" : ");
93 System.out.print("[ "+host.absName+" "+host.name+" "+host.port+" "+host.connectionName+" "+host.reverseName+" "+host.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();
94 } 109 }
95 System.out.println();
96 } 110 }
111
97 ods.put(info1.key, topology); 112 ods.put(info1.key, topology);
98 ods.put(info2.key, info2.getReceiveData()); 113 ods.put(info2.key, info2.getReceiveData());
99 ods.put(info3.key, nameTable); 114 ods.put(info3.key, nameTable);
100 ods.put(info4.key, manager); 115 ods.put(info4.key, manager);
101 } 116 }