changeset 434:4c62f76894c8 dispose

refactoring
author sugi
date Mon, 11 Aug 2014 18:45:33 +0900
parents e565d481c52e
children 41bb86275910
files src/main/java/alice/topology/manager/CheckComingHost.java src/main/java/alice/topology/manager/IncomingHosts.java src/main/java/alice/topology/manager/StartTopologyManager.java
diffstat 3 files changed, 28 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- 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<HostMessage> messageList = this.messageList.asClass(LinkedList.class);
+        HashMap<String, String> 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();
     }
 
 }
--- 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<String, LinkedList<NodeInfo>> topology;
     LinkedList<String> 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<String, LinkedList<NodeInfo>> 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<HostMessage> messageList = this.messageList.asClass(LinkedList.class);
+        HashMap<String, String> 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);
 
--- 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<HostMessage>());
+        ods.put("absCookieTable", new HashMap<String, String>());
         new CreateHash();
     }