annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
433
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
1 package alice.topology.manager;
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
2
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
3 import java.util.LinkedList;
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
4
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
5 import alice.codesegment.CodeSegment;
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
6 import alice.datasegment.CommandType;
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
7 import alice.datasegment.Receiver;
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
8 import alice.topology.HostMessage;
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
9
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
10 public class CheckComingHost extends CodeSegment {
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
11 // checkIncomingHost
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
12 private Receiver host = ids.create(CommandType.TAKE);
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
13 private Receiver messageList = ids.create(CommandType.PEEK); // HostMessage List
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
14
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
15 public CheckComingHost(){
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
16 this.host.setKey("host");
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
17 this.messageList.setKey("messageList");
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
18 }
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
19
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
20 @Override
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
21 public void run() {
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
22 HostMessage host = this.host.asClass(HostMessage.class);
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
23 @SuppressWarnings("unchecked")
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
24 LinkedList<HostMessage> messageList = this.messageList.asClass(LinkedList.class);
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
25 boolean match = false;
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
26 // check cookie
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
27 if (host.cookie != null) {
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
28 for (HostMessage hostMessage : messageList) {
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
29 if (host.cookie.equals(hostMessage.cookie)) {
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
30 match = true;
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
31 host.absName = hostMessage.absName;
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
32 break;
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
33 }
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
34 }
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
35 }
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
36
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
37 if (match){
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
38 // coming host has ever joined this App
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
39 System.out.println("reconnect host");
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
40 ods.put("reconnectHost", host);
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
41 } else {
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
42 System.out.println("new host");
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
43 ods.put("orderHash", "order");
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
44 ods.put("newHost", host);
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
45 }
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
46
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
47 new CheckComingHost();
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
48 }
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
49
e565d481c52e separate checking process from IncomingHosts
sugi
parents:
diff changeset
50 }