Mercurial > hg > Database > Alice
changeset 424:faae3e976cc1 dispose
change cookie LinkedLIst Type from String.class to HostMessage.class
author | sugi |
---|---|
date | Mon, 21 Jul 2014 21:38:43 +0900 |
parents | af343b2a7a8b |
children | 3fff2edc8d33 |
files | src/main/java/alice/topology/HostMessage.java src/main/java/alice/topology/manager/IncomingHosts.java src/main/java/alice/topology/manager/StartTopologyManager.java |
diffstat | 3 files changed, 32 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/alice/topology/HostMessage.java Mon Jul 21 18:55:55 2014 +0900 +++ b/src/main/java/alice/topology/HostMessage.java Mon Jul 21 21:38:43 2014 +0900 @@ -11,6 +11,7 @@ public String reverseName; public String absName; public String parentAbsName; + public String cookie; public HostMessage() { } public HostMessage(String name, int port) {
--- a/src/main/java/alice/topology/manager/IncomingHosts.java Mon Jul 21 18:55:55 2014 +0900 +++ b/src/main/java/alice/topology/manager/IncomingHosts.java Mon Jul 21 21:38:43 2014 +0900 @@ -17,26 +17,43 @@ HashMap<String, LinkedList<NodeInfo>> topology; LinkedList<String> nodeNames; private Receiver host = ids.create(CommandType.TAKE); - private Receiver cookies = ids.create(CommandType.TAKE); + private Receiver nodes = ids.create(CommandType.TAKE); public IncomingHosts(HashMap<String, LinkedList<NodeInfo>> topology, LinkedList<String> nodeNames) { this.topology = topology; this.nodeNames = nodeNames; this.host.setKey("host"); - this.cookies.setKey("cookies"); + this.nodes.setKey("nodes"); } @Override public void run() { HostMessage host = this.host.asClass(HostMessage.class); + // check cookie + if (host.cookie != null) { + @SuppressWarnings("unchecked") + LinkedList<HostMessage> nodes = this.nodes.asClass(LinkedList.class); + for (HostMessage node : nodes) { + if (host.cookie.equals(node.cookie)) { + host.absName = node.absName; + ods.put("reconnect", host); + ods.put(this.nodes.key, nodes); + new SearchHostName(); + } + } + } + // 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); - ods.put(nodeName, "cookie", createCookie()); + + String cookie = createCookie(nodeName); + ods.put(nodeName, "cookie", cookie); + LinkedList<NodeInfo> nodes = topology.get(nodeName); for (NodeInfo nodeInfo : nodes) { HostMessage newHost = new HostMessage(host.name, host.port, @@ -57,23 +74,26 @@ } } - private String createCookie() { + private String createCookie(String hostName) { @SuppressWarnings("unchecked") - LinkedList<String> cookies = this.cookies.asClass(LinkedList.class); + LinkedList<HostMessage> nodes = this.nodes.asClass(LinkedList.class); boolean checkNewCookie = false; String str = null; while (!checkNewCookie){ str = RandomStringUtils.randomAscii(10); int count = 0; - for (String cookie : cookies) { - if (str.equals(cookie)) break; + for (HostMessage node : nodes) { + if (str.equals(node.cookie)) break; count++; } - if (count == cookies.size()) + if (count == nodes.size()) checkNewCookie = true; } - cookies.add(str); - ods.put(this.cookies.key, cookies); + HostMessage table = new HostMessage(); + table.absName = hostName; + table.cookie = str; + nodes.add(table); + ods.put(this.nodes.key, nodes); System.out.println(str); return str; }
--- a/src/main/java/alice/topology/manager/StartTopologyManager.java Mon Jul 21 18:55:55 2014 +0900 +++ b/src/main/java/alice/topology/manager/StartTopologyManager.java Mon Jul 21 21:38:43 2014 +0900 @@ -79,7 +79,7 @@ // for recode topology information ods.put("topology", new HashMap<String, LinkedList<HostMessage>>()); // cookie List - ods.put("cookies", new LinkedList<String>()); + ods.put("nodes", new LinkedList<String>()); new IncomingHosts(topology, nodeNames);