Mercurial > hg > Database > Alice
changeset 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 |
files | src/main/java/alice/topology/fix/FixTopology.java src/main/java/alice/topology/manager/Parent.java src/main/java/alice/topology/manager/ParentManager.java |
diffstat | 3 files changed, 60 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/alice/topology/fix/FixTopology.java Tue Dec 02 13:43:07 2014 +0900 +++ b/src/main/java/alice/topology/fix/FixTopology.java Tue Dec 02 14:49:20 2014 +0900 @@ -18,7 +18,6 @@ private Receiver info3 = ids.create(CommandType.TAKE); // IP Table private Receiver info4 = ids.create(CommandType.TAKE); // parentManager - public FixTopology() { info.setKey("_DISCONNECT"); info1.setKey("topology"); @@ -32,30 +31,32 @@ public void run() { ConnectionInfo disconnect = info.asClass(ConnectionInfo.class); HashMap<String, HostMessage> nameTable = info3.asClass(HashMap.class); + ParentManager manager = info4.asClass(ParentManager.class); HostMessage disconnectNode = nameTable.get(disconnect.nodeName); + HashMap<String, LinkedList<HostMessage>> topology = info1.asClass(HashMap.class); + if (disconnectNode.isAlive()) { // change state not Alive disconnectNode.alive = false; // get lastJoinedNode int last = info2.asInteger()-1; String lastJoinedNode = "node"+last; - if (!lastJoinedNode.equals(disconnect.nodeName)) { - HashMap<String, LinkedList<HostMessage>> topology = info1.asClass(HashMap.class); + LinkedList<HostMessage> connectionList = topology.get(lastJoinedNode); + // lastJoinedNode has one connection + HostMessage parentInfo = connectionList.poll(); - LinkedList<HostMessage> connectionList = topology.get(lastJoinedNode); - // lastJoinedNode has one connection - HostMessage parentInfo = connectionList.poll(); + for (HostMessage node1 : topology.get(parentInfo.absName)) { + if (node1.remoteAbsName.equals(lastJoinedNode)) { + list.remove(node1); + break; + } + } + + if (!lastJoinedNode.equals(disconnect.nodeName)) { // send close message to lastJoinedNode ods.put(lastJoinedNode, "_CLOSEMESSEAGE", parentInfo.reverseName); - // send close message to lastJoinedNode's parent ods.put(parentInfo.absName, "_CLOSEMESSEAGE", parentInfo.connectionName); - for (HostMessage node1 : topology.get(parentInfo.absName)) { - if (node1.remoteAbsName.equals(lastJoinedNode)) { - list.remove(node1); - break; - } - } HostMessage lastJoined = nameTable.get(lastJoinedNode); LinkedList<HostMessage> disconnectionList = topology.get(disconnect.nodeName); @@ -75,11 +76,18 @@ ods.put(lastJoinedNode, node); connectionList.add(node); } + + manager.replaceAndRemove(disconnect.nodeName, lastJoinedNode); } else { // disconnection node is lastJoinedNode + manager.remove(disconnect.nodeName); } } else { // disconnect message already received. } + ods.put(info1.key, topology); + ods.put(info2.key, info2.getReceiveData()); + ods.put(info3.key, nameTable); + ods.put(info4.key, manager); } }
--- a/src/main/java/alice/topology/manager/Parent.java Tue Dec 02 13:43:07 2014 +0900 +++ b/src/main/java/alice/topology/manager/Parent.java Tue Dec 02 14:49:20 2014 +0900 @@ -12,10 +12,18 @@ return children; } + public void setChildren(int num) { + children = num; + } + public String getName() { return name; } + public void setName(String n) { + name = n; + } + public void increment() { children++; }
--- a/src/main/java/alice/topology/manager/ParentManager.java Tue Dec 02 13:43:07 2014 +0900 +++ b/src/main/java/alice/topology/manager/ParentManager.java Tue Dec 02 14:49:20 2014 +0900 @@ -1,14 +1,14 @@ package alice.topology.manager; -import java.util.ArrayList; +import java.util.LinkedList; public class ParentManager { private int BINARY_TREE = 2; private int position = 0; - private ArrayList<Parent> list; + private LinkedList<Parent> list; public ParentManager(){ - list = new ArrayList<Parent>(); + list = new LinkedList<Parent>(); } public String getMyParent() { @@ -43,7 +43,34 @@ position--; } - public void overwirte(String str, String str1) { + public void replaceAndRemove(String remove, String replace) { + Parent removeNode = find(remove); + remove(replace); + removeNode.setName(replace); + } + + public void remove(String remove) { + Parent removeNode = find(remove); + list.remove(removeNode); + } + + public void decrementChild(String name) { + list.get(position).decrement(); + } + private Parent find(String name) { + boolean found = false; + int i = 0; + for (;i<list.size();i++) { + if (list.get(i).equals(name)) { + found = true; + break; + } + } + if (found) { + return list.get(i); + } else { + return null; + } } }