Mercurial > hg > Database > Alice
changeset 437:b9fd22d9f6c5 dispose
refactoring IncomingHosts.java
author | sugi |
---|---|
date | Mon, 18 Aug 2014 15:54:53 +0900 |
parents | a9ed8e932a1e |
children | c973f7ee7c91 |
files | src/main/java/alice/topology/manager/IncomingHosts.java src/main/java/alice/topology/manager/StartTopologyManager.java |
diffstat | 2 files changed, 50 insertions(+), 58 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/alice/topology/manager/IncomingHosts.java Tue Aug 12 07:57:47 2014 +0900 +++ b/src/main/java/alice/topology/manager/IncomingHosts.java Mon Aug 18 15:54:53 2014 +0900 @@ -13,16 +13,15 @@ public class IncomingHosts extends CodeSegment { - HashMap<String, LinkedList<NodeInfo>> topology; - LinkedList<String> nodeNames; - private Receiver host = ids.create(CommandType.TAKE); //HostMessage + private Receiver topology = ids.create(CommandType.TAKE); // Topology from parse file + private Receiver nodeNames = ids.create(CommandType.TAKE); // nodeName list + private Receiver host = ids.create(CommandType.TAKE); // new coming host info private Receiver absCookieTable = ids.create(CommandType.TAKE); // cookie, AbsName HashMap - private Receiver cookie = ids.create(CommandType.TAKE); // MD5 + private Receiver cookie = ids.create(CommandType.TAKE); // MD5 - public IncomingHosts(HashMap<String, LinkedList<NodeInfo>> topology, - LinkedList<String> nodeNames) { - this.topology = topology; - this.nodeNames = nodeNames; + public IncomingHosts() { + this.topology.setKey("resultParse"); + this.nodeNames.setKey("nodeNames"); this.host.setKey("host"); this.absCookieTable.setKey("absCookieTable"); this.cookie.setKey("MD5"); @@ -33,55 +32,47 @@ HostMessage host = this.host.asClass(HostMessage.class); @SuppressWarnings("unchecked") HashMap<String, String> absCookieTable = this.absCookieTable.asClass(HashMap.class); - boolean match = false; - // check cookie - if (host.cookie != null) { - if (absCookieTable.containsKey(host.cookie)){ - match = true; - System.out.println("cookie is match"); - host.absName = absCookieTable.get(host.cookie); - ods.put("reconnectHost", host); - - ods.put(this.absCookieTable.key, absCookieTable); - new SearchHostName(); - + @SuppressWarnings("unchecked") + HashMap<String, LinkedList<NodeInfo>> topology = this.topology.asClass(HashMap.class); + @SuppressWarnings("unchecked") + LinkedList<String> nodeNames = this.nodeNames.asClass(LinkedList.class); + + + System.out.println("new node come"); + // not have or match cookie + String nodeName = nodeNames.poll(); + // Manager connect to Node + DataSegment.connect(nodeName, "", host.name, host.port); + ods.put(nodeName, "host", nodeName); + + String cookie = this.cookie.asString(); + absCookieTable.put(cookie, nodeName); + ods.put(this.absCookieTable.key, absCookieTable); + + ods.put(nodeName, "cookie", cookie); + + LinkedList<NodeInfo> nodes = topology.get(nodeName); + for (NodeInfo nodeInfo : nodes) { + HostMessage newHost = new HostMessage(host.name, host.port, + nodeInfo.connectionName, nodeInfo.reverseName); + newHost.absName = nodeName; + newHost.remoteAbsName = nodeInfo.sourceNodeName; + + ods.put("nodeInfo", newHost); + ods.put(nodeInfo.sourceNodeName, newHost); + new RecodeTopology(); + } + + if (nodeNames.isEmpty()) { + // configuration finish + for (String key : topology.keySet()) { + ods.put("local", key, ValueFactory.createNilValue()); } } - if (!match) { - System.out.println("new node come"); - // not have or match cookie - String nodeName = nodeNames.poll(); - // Manager connect to Node - DataSegment.connect(nodeName, "", host.name, host.port); - ods.put(nodeName, "host", nodeName); - - String cookie = this.cookie.asString(); - absCookieTable.put(cookie, nodeName); - ods.put(this.absCookieTable.key, absCookieTable); - - ods.put(nodeName, "cookie", cookie); - - LinkedList<NodeInfo> nodes = topology.get(nodeName); - for (NodeInfo nodeInfo : nodes) { - HostMessage newHost = new HostMessage(host.name, host.port, - nodeInfo.connectionName, nodeInfo.reverseName); - newHost.absName = nodeName; - newHost.remoteAbsName = nodeInfo.sourceNodeName; - - ods.put("nodeInfo", newHost); - ods.put(nodeInfo.sourceNodeName, newHost); - new RecodeTopology(); - } - - if (nodeNames.isEmpty()) { - // configuration finish - for (String key : topology.keySet()) { - ods.put("local", key, ValueFactory.createNilValue()); - } - } - } + ods.put(this.nodeNames.key, nodeNames); + ods.put(this.topology.key, topology); ods.put("orderHash", "order"); - new IncomingHosts(topology, nodeNames); + new IncomingHosts(); } }
--- a/src/main/java/alice/topology/manager/StartTopologyManager.java Tue Aug 12 07:57:47 2014 +0900 +++ b/src/main/java/alice/topology/manager/StartTopologyManager.java Mon Aug 18 15:54:53 2014 +0900 @@ -78,15 +78,16 @@ // for recode topology information // cookie List + ods.put("running", false); + ods.put("resultParse", topology); + ods.put("nodeNames", nodeNames); ods.put("orderHash", "order"); - ods.put("running", false); - - new IncomingHosts(topology, nodeNames); + new IncomingHosts(); ConfigWaiter cs3 = new ConfigWaiter(nodeNum); cs3.done.setKey("local", "done"); + } else { - System.out.println("mode -t"); ods.put("running", true); new CheckComingHost();