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