Mercurial > hg > Database > Alice
view src/main/java/alice/topology/manager/CreateTreeTopology.java @ 517:80e461aa10e9 dispose
bug fix
author | sugi |
---|---|
date | Thu, 22 Jan 2015 11:43:34 +0900 |
parents | 6161dcd3da02 |
children | fc313323c53b |
line wrap: on
line source
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(); 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 = null; int count = comingHostCount; boolean reconnect = false; if (host.absName!=null) { System.out.println(host.cookie); cookie = host.cookie; nodeName = host.absName; System.out.println(nodeName); reconnect = true; } else { System.out.println(cookie); nodeName = "node"+comingHostCount; absCookieTable.put(cookie, nodeName); count++; } // Manager connect to Node DataSegment.connect(nodeName, nodeName, host.name, host.port); ods.put(nodeName, "host", nodeName); ods.put(nodeName, "cookie", cookie); ods.put(info4.key, absCookieTable); ods.put(info1.key, count); 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); if (reconnect) 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()); } }