Mercurial > hg > Database > Alice
changeset 514:6732d03d0174 dispose
refactor TopologyFix has bug
author | sugi |
---|---|
date | Sat, 17 Jan 2015 16:49:02 +0900 |
parents | 6a9886c13f45 |
children | 6161dcd3da02 |
files | src/main/java/alice/topology/manager/ComingServiceHosts.java src/main/java/alice/topology/manager/CreateTreeTopology.java src/main/java/alice/topology/manager/ParentManager.java src/main/java/alice/topology/manager/SendNodeInfo.java src/main/java/alice/topology/manager/StartTopologyManager.java src/main/java/alice/topology/manager/TopologyManagerConfig.java src/main/java/alice/topology/manager/TopologyType.java |
diffstat | 7 files changed, 124 insertions(+), 97 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/alice/topology/manager/ComingServiceHosts.java Sat Jan 10 18:19:35 2015 +0900 +++ b/src/main/java/alice/topology/manager/ComingServiceHosts.java Sat Jan 17 16:49:02 2015 +0900 @@ -14,7 +14,7 @@ @Override public void run() { - new SendNodeInfo(); + new CreateTreeTopology(); new ComingServiceHosts(); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/CreateTreeTopology.java Sat Jan 17 16:49:02 2015 +0900 @@ -0,0 +1,86 @@ +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 CreateTreeTopology 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 info6 = ids.create(CommandType.TAKE); + + public CreateTreeTopology(){ + info.setKey("newHost"); + info1.setKey("hostCount"); + info2.setKey("nameTable"); + info3.setKey("MD5"); + info4.setKey("absCookieTable"); + info6.setKey("parentManager"); + } + + @SuppressWarnings("unchecked") + @Override + public void run() { + String cookie = info3.asString(); + System.out.println(cookie); + HostMessage host = info.asClass(HostMessage.class); + int comingHostCount = info1.asInteger(); + ParentManager manager = info6.asClass(ParentManager.class); + + HashMap<String, HostMessage> nameTable = info2.asClass(HashMap.class); + HashMap<String, String> absCookieTable = info4.asClass(HashMap.class); + + String nodeName = "node"+comingHostCount; + // Manager connect to Node + DataSegment.connect(nodeName, 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.put(info1.key, comingHostCount+1); + host.alive = true; + nameTable.put(nodeName, host); + manager.register(nodeName); + + if (comingHostCount!=0) { + // 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); + + 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(); + + } + + 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/ParentManager.java Sat Jan 10 18:19:35 2015 +0900 +++ b/src/main/java/alice/topology/manager/ParentManager.java Sat Jan 17 16:49:02 2015 +0900 @@ -4,11 +4,12 @@ public class ParentManager { - private int BINARY_TREE = 2; + private int maxChildren; private int position = 0; private LinkedList<Parent> list; - public ParentManager(){ + public ParentManager(int hasChildren){ list = new LinkedList<Parent>(); + maxChildren = hasChildren; } public String getMyParent() { @@ -25,7 +26,7 @@ private void checkChildNumber() { for (;;next()) { - if (list.get(position).children() < BINARY_TREE) + if (list.get(position).children() < maxChildren) break; } }
--- a/src/main/java/alice/topology/manager/SendNodeInfo.java Sat Jan 10 18:19:35 2015 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -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 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 info6 = ids.create(CommandType.TAKE); - - public SendNodeInfo(){ - info.setKey("newHost"); - info1.setKey("hostCount"); - info2.setKey("nameTable"); - info3.setKey("MD5"); - info4.setKey("absCookieTable"); - info6.setKey("parentManager"); - } - - @SuppressWarnings("unchecked") - @Override - public void run() { - String cookie = info3.asString(); - System.out.println(cookie); - HostMessage host = info.asClass(HostMessage.class); - int comingHostCount = info1.asInteger(); - ParentManager manager = info6.asClass(ParentManager.class); - - HashMap<String, HostMessage> nameTable = info2.asClass(HashMap.class); - HashMap<String, String> absCookieTable = info4.asClass(HashMap.class); - - String nodeName = "node"+comingHostCount; - // Manager connect to Node - DataSegment.connect(nodeName, 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.put(info1.key, comingHostCount+1); - host.alive = true; - nameTable.put(nodeName, host); - manager.register(nodeName); - - if (comingHostCount!=0) { - // 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); - - 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(); - - } - - 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 Sat Jan 10 18:19:35 2015 +0900 +++ b/src/main/java/alice/topology/manager/StartTopologyManager.java Sat Jan 17 16:49:02 2015 +0900 @@ -95,13 +95,16 @@ ods.put("running", true); HashMap<String, HostMessage> nameTable = new HashMap<String, HostMessage>(); - int cominghostCount = 0; - ParentManager manager = new ParentManager(); - ods.put("parentManager", manager); - ods.put("nameTable", nameTable); - ods.put("hostCount", cominghostCount); - new ComingServiceHosts(); - new ReceiveDisconnectMessage(); + + if (conf.type == TopologyType.Tree) { + int cominghostCount = 0; + ParentManager manager = new ParentManager(conf.hasChild); + ods.put("parentManager", manager); + ods.put("nameTable", nameTable); + ods.put("hostCount", cominghostCount); + new ComingServiceHosts(); + new ReceiveDisconnectMessage(); + } } ods.put("topology", new HashMap<String, LinkedList<HostMessage>>());
--- a/src/main/java/alice/topology/manager/TopologyManagerConfig.java Sat Jan 10 18:19:35 2015 +0900 +++ b/src/main/java/alice/topology/manager/TopologyManagerConfig.java Sat Jan 17 16:49:02 2015 +0900 @@ -6,12 +6,21 @@ public String confFilePath; public boolean dynamic = false; + public TopologyType type = TopologyType.Tree; + public int hasChild = 2; public TopologyManagerConfig(String[] args) { super(args); for (int i = 0; i < args.length; i++) { if ("-conf".equals(args[i])) { confFilePath = args[++i]; + } else if ("--Topology".equals(args[i])) { + String typeName = args[++i]; + if ("tree".equals(typeName)) { + type = TopologyType.Tree; + } + } else if ("--Child".equals(args[i])) { + hasChild = Integer.parseInt(args[++i]); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/TopologyType.java Sat Jan 17 16:49:02 2015 +0900 @@ -0,0 +1,14 @@ +package alice.topology.manager; + +public enum TopologyType { + Tree(1); + + private final int id; + private TopologyType(final int id) { + this.id = id; + } + + public int getId() { + return id; + } +}