Mercurial > hg > Database > Alice
diff src/main/java/alice/topology/manager/CheckComingHost.java @ 433:e565d481c52e dispose
separate checking process from IncomingHosts
author | sugi |
---|---|
date | Mon, 11 Aug 2014 18:23:18 +0900 |
parents | |
children | 4c62f76894c8 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/alice/topology/manager/CheckComingHost.java Mon Aug 11 18:23:18 2014 +0900 @@ -0,0 +1,50 @@ +package alice.topology.manager; + +import java.util.LinkedList; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.Receiver; +import alice.topology.HostMessage; + +public class CheckComingHost extends CodeSegment { + // checkIncomingHost + private Receiver host = ids.create(CommandType.TAKE); + private Receiver messageList = ids.create(CommandType.PEEK); // HostMessage List + + public CheckComingHost(){ + this.host.setKey("host"); + this.messageList.setKey("messageList"); + } + + @Override + public void run() { + HostMessage host = this.host.asClass(HostMessage.class); + @SuppressWarnings("unchecked") + LinkedList<HostMessage> messageList = this.messageList.asClass(LinkedList.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 (match){ + // coming host has ever joined this App + System.out.println("reconnect host"); + ods.put("reconnectHost", host); + } else { + System.out.println("new host"); + ods.put("orderHash", "order"); + ods.put("newHost", host); + } + + new CheckComingHost(); + } + +}