# HG changeset patch # User sugi # Date 1407750333 -32400 # Node ID 4c62f76894c817cdbea5d37211b08764528b9711 # Parent e565d481c52ede042f7d70bc0b9dd4eb81bde16b refactoring diff -r e565d481c52e -r 4c62f76894c8 src/main/java/alice/topology/manager/CheckComingHost.java --- a/src/main/java/alice/topology/manager/CheckComingHost.java Mon Aug 11 18:23:18 2014 +0900 +++ b/src/main/java/alice/topology/manager/CheckComingHost.java Mon Aug 11 18:45:33 2014 +0900 @@ -1,7 +1,6 @@ package alice.topology.manager; -import java.util.LinkedList; - +import java.util.HashMap; import alice.codesegment.CodeSegment; import alice.datasegment.CommandType; import alice.datasegment.Receiver; @@ -10,30 +9,28 @@ public class CheckComingHost extends CodeSegment { // checkIncomingHost private Receiver host = ids.create(CommandType.TAKE); - private Receiver messageList = ids.create(CommandType.PEEK); // HostMessage List - + private Receiver absCookieTable = ids.create(CommandType.TAKE); // cookie, AbsName HashMap + public CheckComingHost(){ this.host.setKey("host"); - this.messageList.setKey("messageList"); + this.absCookieTable.setKey("absCookieTable"); } - + @Override public void run() { HostMessage host = this.host.asClass(HostMessage.class); @SuppressWarnings("unchecked") - LinkedList messageList = this.messageList.asClass(LinkedList.class); + HashMap absCookieTable = this.absCookieTable.asClass(HashMap.class); boolean match = false; // check cookie if (host.cookie != null) { - for (HostMessage hostMessage : messageList) { - if (host.cookie.equals(hostMessage.cookie)) { - match = true; - host.absName = hostMessage.absName; - break; - } + if (absCookieTable.containsKey(host.cookie)){ + match = true; + host.absName = absCookieTable.get(host.cookie); + } } - + if (match){ // coming host has ever joined this App System.out.println("reconnect host"); @@ -43,8 +40,8 @@ ods.put("orderHash", "order"); ods.put("newHost", host); } - - new CheckComingHost(); + + new CheckComingHost(); } } diff -r e565d481c52e -r 4c62f76894c8 src/main/java/alice/topology/manager/IncomingHosts.java --- a/src/main/java/alice/topology/manager/IncomingHosts.java Mon Aug 11 18:23:18 2014 +0900 +++ b/src/main/java/alice/topology/manager/IncomingHosts.java Mon Aug 11 18:45:33 2014 +0900 @@ -16,7 +16,7 @@ HashMap> topology; LinkedList nodeNames; private Receiver host = ids.create(CommandType.TAKE); //HostMessage - private Receiver messageList = ids.create(CommandType.TAKE); // HostMessage List + private Receiver absCookieTable = ids.create(CommandType.TAKE); // cookie, AbsName HashMap private Receiver cookie = ids.create(CommandType.TAKE); // MD5 public IncomingHosts(HashMap> topology, @@ -24,7 +24,7 @@ this.topology = topology; this.nodeNames = nodeNames; this.host.setKey("host"); - this.messageList.setKey("messageList"); + this.absCookieTable.setKey("absCookieTable"); this.cookie.setKey("MD5"); } @@ -32,20 +32,19 @@ public void run() { HostMessage host = this.host.asClass(HostMessage.class); @SuppressWarnings("unchecked") - LinkedList messageList = this.messageList.asClass(LinkedList.class); + HashMap absCookieTable = this.absCookieTable.asClass(HashMap.class); boolean match = false; // check cookie if (host.cookie != null) { - for (HostMessage hostMessage : messageList) { - if (host.cookie.equals(hostMessage.cookie)) { - match = true; - System.out.println("cookie is match"); - host.absName = hostMessage.absName; - ods.put("reconnectHost", host); - ods.put(this.messageList.key, messageList); - new SearchHostName(); - break; - } + 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(); + } } @@ -58,11 +57,8 @@ ods.put(nodeName, "host", nodeName); String cookie = this.cookie.asString(); - HostMessage record = new HostMessage(); - record.absName = nodeName; - record.cookie = cookie; - messageList.add(record); - ods.put(this.messageList.key, messageList); + absCookieTable.put(cookie, nodeName); + ods.put(this.absCookieTable.key, absCookieTable); ods.put(nodeName, "cookie", cookie); diff -r e565d481c52e -r 4c62f76894c8 src/main/java/alice/topology/manager/StartTopologyManager.java --- a/src/main/java/alice/topology/manager/StartTopologyManager.java Mon Aug 11 18:23:18 2014 +0900 +++ b/src/main/java/alice/topology/manager/StartTopologyManager.java Mon Aug 11 18:45:33 2014 +0900 @@ -98,7 +98,7 @@ new ComingServiceHosts(); } - ods.put("messageList", new LinkedList()); + ods.put("absCookieTable", new HashMap()); new CreateHash(); }