Mercurial > hg > Database > Alice
changeset 472:116e0fde9233 dispose
change algotherm
author | sugi |
---|---|
date | Tue, 25 Nov 2014 16:17:33 +0900 |
parents | be0b61986ff7 |
children | 041ec04d4d45 |
files | src/main/java/alice/topology/manager/ComingServiceHosts.java src/main/java/alice/topology/manager/RecodeTopology.java src/main/java/alice/topology/manager/SendNodeInfo.java |
diffstat | 3 files changed, 113 insertions(+), 65 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/alice/topology/manager/ComingServiceHosts.java Mon Nov 24 22:57:40 2014 +0900 +++ b/src/main/java/alice/topology/manager/ComingServiceHosts.java Tue Nov 25 16:17:33 2014 +0900 @@ -1,82 +1,21 @@ package alice.topology.manager; -import java.util.HashMap; - -import org.msgpack.type.ValueFactory; - import alice.codesegment.CodeSegment; import alice.datasegment.CommandType; -import alice.datasegment.DataSegment; import alice.datasegment.Receiver; -import alice.topology.HostMessage; public class ComingServiceHosts extends CodeSegment{ - private Receiver info = ids.create(CommandType.TAKE); - private Receiver info1 = ids.create(CommandType.TAKE); - private Receiver info2 = ids.create(CommandType.TAKE); // HashMap - private Receiver info3 = ids.create(CommandType.TAKE); // MD5 - private Receiver info4 = ids.create(CommandType.TAKE); - - private int BINATY_TREE = 2; + private Receiver info = ids.create(CommandType.PEEK); public ComingServiceHosts(){ info.setKey("newHost"); - info1.setKey("hostCount"); - info2.setKey("nodeConnectionInfo"); - info3.setKey("MD5"); - info4.setKey("absCookieTable"); } @Override public void run() { - String cookie = info3.asString(); - System.out.println(cookie); - HostMessage host = info.asClass(HostMessage.class); - int comingHostCount = info1.asInteger(); - @SuppressWarnings("unchecked") - HashMap<String, HostMessage> parentInfo = info2.asClass(HashMap.class); - @SuppressWarnings("unchecked") - HashMap<String, String> absCookieTable = info4.asClass(HashMap.class); - String nodeName = "node"+comingHostCount; - // Manager connect to Node - DataSegment.connect(nodeName, "", host.name, host.port); - ods.put(nodeName, "host", nodeName); - ods.put(nodeName, "cookie", cookie); - - absCookieTable.put(cookie, nodeName); - ods.put(info4.key, absCookieTable); - ods.update(info1.key, comingHostCount+1); - - for (int i=1;i < BINATY_TREE+1; i++) { - // child number is own number(comingHostCount) * 2 add one or two - 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); - - ods.put("nodeInfo", newHost); - ods.put(newHost.remoteAbsName, newHost); - new RecodeTopology(); - } - 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("nodeInfo", newHost); - ods.put(parent.absName, newHost); - new RecodeTopology(); - } - - ods.put("nodeConnectionInfo", parentInfo); - ods.put(nodeName, ValueFactory.createNilValue()); - if (comingHostCount==0) - ods.put("start", ValueFactory.createNilValue()); - - this.recycle(); + new SendNodeInfo(); + new ComingServiceHosts(); } }
--- a/src/main/java/alice/topology/manager/RecodeTopology.java Mon Nov 24 22:57:40 2014 +0900 +++ b/src/main/java/alice/topology/manager/RecodeTopology.java Tue Nov 25 16:17:33 2014 +0900 @@ -15,7 +15,7 @@ public RecodeTopology(){ info.setKey("nodeInfo"); - info1.setKey("topology"); + } @Override
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/SendNodeInfo.java Tue Nov 25 16:17:33 2014 +0900 @@ -0,0 +1,109 @@ +package alice.topology.manager; + +import java.util.HashMap; +import java.util.LinkedList; + +import org.msgpack.type.ValueFactory; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.DataSegment; +import alice.datasegment.Receiver; +import alice.topology.HostMessage; + +public class SendNodeInfo extends CodeSegment{ + + private Receiver info = ids.create(CommandType.TAKE); + private Receiver info1 = ids.create(CommandType.TAKE); + 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 int BINATY_TREE = 2; + + public SendNodeInfo(){ + info.setKey("newHost"); + info1.setKey("hostCount"); + info2.setKey("nodeConnectionInfo"); + info3.setKey("MD5"); + info4.setKey("absCookieTable"); + info5.setKey("topology"); + } + + @SuppressWarnings("unchecked") + @Override + public void run() { + String cookie = info3.asString(); + System.out.println(cookie); + HostMessage host = info.asClass(HostMessage.class); + int comingHostCount = info1.asInteger(); + + HashMap<String, HostMessage> parentInfo = 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 + DataSegment.connect(nodeName, "", host.name, host.port); + ods.put(nodeName, "host", nodeName); + ods.put(nodeName, "cookie", cookie); + + 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); + } + + 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); + + 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); + } + + 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(nodeName, ValueFactory.createNilValue()); + if (comingHostCount==0) + ods.put("start", ValueFactory.createNilValue()); + } + +} \ No newline at end of file