Mercurial > hg > Database > Alice
changeset 475:fac27e395930 dispose
change decide children algorithm
author | sugi |
---|---|
date | Mon, 01 Dec 2014 17:32:54 +0900 |
parents | 6a71732cd3ee |
children | 8968b24c1ce3 |
files | src/main/java/alice/topology/HostMessage.java src/main/java/alice/topology/manager/Parent.java src/main/java/alice/topology/manager/ParentManager.java src/main/java/alice/topology/manager/RecodeTopology.java src/main/java/alice/topology/manager/SendNodeInfo.java src/main/java/alice/topology/manager/StartTopologyManager.java |
diffstat | 6 files changed, 111 insertions(+), 62 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/alice/topology/HostMessage.java Sun Nov 30 00:01:35 2014 +0900 +++ b/src/main/java/alice/topology/HostMessage.java Mon Dec 01 17:32:54 2014 +0900 @@ -4,13 +4,13 @@ @Message public class HostMessage { - public String name; public int port; + public String connectionName; + public String absName; // this is absName which have these IP and port. + public String reverseName; - - public String absName; public String remoteAbsName; public String cookie; // MD5 @@ -26,5 +26,4 @@ this.connectionName = connectionName; this.reverseName = reverseName; } - }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/Parent.java Mon Dec 01 17:32:54 2014 +0900 @@ -0,0 +1,27 @@ +package alice.topology.manager; + +public class Parent { + private String name; + private int children = 0; + + public Parent(String name) { + this.name = name; + } + + public int children() { + return children; + } + + public String getName() { + return name; + } + + public void increment() { + children++; + } + + public void decrement() { + children--; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/ParentManager.java Mon Dec 01 17:32:54 2014 +0900 @@ -0,0 +1,45 @@ +package alice.topology.manager; + +import java.util.ArrayList; + +public class ParentManager { + + private int BINARY_TREE = 2; + private int position = 0; + private ArrayList<Parent> list; + public ParentManager(){ + list = new ArrayList<Parent>(); + } + + public String getMyParent() { + checkChildNumber(); + return list.get(position).getName(); + } + + public int getMyNumber() { + checkChildNumber(); + int num = list.get(position).children(); + list.get(position).increment(); + return num; + } + + private void checkChildNumber() { + for (;;position++) { + if (list.get(position).children() < BINARY_TREE) + break; + } + } + + public void register(String name) { + Parent p = new Parent(name); + list.add(p); + } + + public void next() { + position++; + } + + public void previous() { + position--; + } +}
--- a/src/main/java/alice/topology/manager/RecodeTopology.java Sun Nov 30 00:01:35 2014 +0900 +++ b/src/main/java/alice/topology/manager/RecodeTopology.java Mon Dec 01 17:32:54 2014 +0900 @@ -15,7 +15,7 @@ public RecodeTopology(){ info.setKey("nodeInfo"); - + info1.setKey("topology"); } @Override
--- a/src/main/java/alice/topology/manager/SendNodeInfo.java Sun Nov 30 00:01:35 2014 +0900 +++ b/src/main/java/alice/topology/manager/SendNodeInfo.java Mon Dec 01 17:32:54 2014 +0900 @@ -1,8 +1,6 @@ package alice.topology.manager; import java.util.HashMap; -import java.util.LinkedList; - import org.msgpack.type.ValueFactory; import alice.codesegment.CodeSegment; @@ -18,17 +16,15 @@ private Receiver info2 = ids.create(CommandType.TAKE); // HashMap private Receiver info3 = ids.create(CommandType.TAKE); // MD5 private Receiver info4 = ids.create(CommandType.TAKE); - private Receiver info5 = ids.create(CommandType.TAKE); - - private static int BINATY_TREE = 2; + private Receiver info6 = ids.create(CommandType.TAKE); public SendNodeInfo(){ info.setKey("newHost"); info1.setKey("hostCount"); - info2.setKey("nodeConnectionInfo"); + info2.setKey("nameTable"); info3.setKey("MD5"); info4.setKey("absCookieTable"); - info5.setKey("topology"); + info6.setKey("parentManager"); } @SuppressWarnings("unchecked") @@ -38,10 +34,10 @@ System.out.println(cookie); HostMessage host = info.asClass(HostMessage.class); int comingHostCount = info1.asInteger(); + ParentManager manager = info6.asClass(ParentManager.class); - HashMap<String, HostMessage> parentInfo = info2.asClass(HashMap.class); + HashMap<String, HostMessage> nameTable = info2.asClass(HashMap.class); HashMap<String, String> absCookieTable = info4.asClass(HashMap.class); - HashMap<String, LinkedList<HostMessage>> topology = info5.asClass(HashMap.class); String nodeName = "node"+comingHostCount; // Manager connect to Node @@ -51,59 +47,39 @@ absCookieTable.put(cookie, nodeName); ods.put(info4.key, absCookieTable); - ods.update(info1.key, comingHostCount+1); - - /* - * add List own NodeInfo to own child - * child number is own number(comingHostCount) * 2 add one or two - */ - for (int i=1;i < BINATY_TREE+1; i++) { - int num = BINATY_TREE * comingHostCount+i; - HostMessage newHost = new HostMessage(host.name, host.port, "parent", "child"+(i-1)); - newHost.absName = nodeName; - newHost.remoteAbsName = "node"+num; - parentInfo.put(newHost.remoteAbsName, newHost); - - LinkedList<HostMessage> connections; - if (!topology.containsKey(newHost.remoteAbsName)) { - connections = new LinkedList<HostMessage>(); - } else { - connections = topology.get(newHost.remoteAbsName); - } - connections.add(newHost); - topology.put(newHost.remoteAbsName, connections); - } + ods.put(info1.key, comingHostCount+1); + nameTable.put(nodeName, host); + manager.register(nodeName); if (comingHostCount!=0) { - HostMessage parent = parentInfo.get(nodeName); - HostMessage newHost = new HostMessage(host.name, host.port, parent.reverseName, parent.connectionName); - newHost.absName = nodeName; - newHost.remoteAbsName = parent.absName; - ods.put(parent.absName, newHost); + // put parent information own + String parentAbsName = manager.getMyParent(); + HostMessage parent = nameTable.get(parentAbsName); + int num = manager.getMyNumber(); + + HostMessage newHost = new HostMessage(parent.name, parent.port, "parent", "child"+num); + newHost.absName = parentAbsName; + newHost.remoteAbsName = nodeName; // address + ods.put(newHost.remoteAbsName, newHost); - LinkedList<HostMessage> connections; - if (!topology.containsKey(newHost.remoteAbsName)) { - connections = new LinkedList<HostMessage>(); - } else { - connections = topology.get(newHost.remoteAbsName); - } - connections.add(newHost); - topology.put(newHost.remoteAbsName, connections); + ods.put("nodeInfo", newHost); + new RecodeTopology(); + + // put own information parent + newHost = new HostMessage(host.name, host.port, "child"+num, "parent"); + newHost.absName = nodeName; + newHost.remoteAbsName = parentAbsName; + + ods.put(newHost.remoteAbsName, newHost); + ods.put("nodeInfo", newHost); + new RecodeTopology(); + } - LinkedList<HostMessage> connections; - if (topology.containsKey(nodeName)) { - connections = topology.get(nodeName); - for (HostMessage node :connections) { - ods.put(nodeName, node); - } - } - - ods.put(info5.key, topology); - ods.put("nodeConnectionInfo", parentInfo); + ods.put(info2.key, nameTable); + ods.put(info6.key, manager); ods.put(nodeName, ValueFactory.createNilValue()); if (comingHostCount==0) ods.put("start", ValueFactory.createNilValue()); } - } \ No newline at end of file
--- a/src/main/java/alice/topology/manager/StartTopologyManager.java Sun Nov 30 00:01:35 2014 +0900 +++ b/src/main/java/alice/topology/manager/StartTopologyManager.java Mon Dec 01 17:32:54 2014 +0900 @@ -93,9 +93,11 @@ } else { ods.put("running", true); - HashMap<String,HostMessage> parentInfo = new HashMap<String,HostMessage>(); + HashMap<String, HostMessage> nameTable = new HashMap<String, HostMessage>(); int cominghostCount = 0; - ods.put("nodeConnectionInfo", parentInfo); + ParentManager manager = new ParentManager(); + ods.put("parentManager", manager); + ods.put("nameTable", nameTable); ods.put("hostCount", cominghostCount); new ComingServiceHosts(); }