433
|
1 package alice.topology.manager;
|
|
2
|
434
|
3 import java.util.HashMap;
|
515
|
4
|
433
|
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
|
466
|
12 private Receiver host = ids.create(CommandType.TAKE);
|
435
|
13 private Receiver absCookieTable = ids.create(CommandType.PEEK); // cookie, AbsName HashMap
|
515
|
14 private Receiver config = ids.create(CommandType.PEEK);
|
434
|
15
|
433
|
16 public CheckComingHost(){
|
|
17 this.host.setKey("host");
|
434
|
18 this.absCookieTable.setKey("absCookieTable");
|
515
|
19 this.config.setKey("TMConfig");
|
433
|
20 }
|
434
|
21
|
433
|
22 @Override
|
|
23 public void run() {
|
|
24 HostMessage host = this.host.asClass(HostMessage.class);
|
|
25 @SuppressWarnings("unchecked")
|
434
|
26 HashMap<String, String> absCookieTable = this.absCookieTable.asClass(HashMap.class);
|
515
|
27 TopologyManagerConfig conf = this.config.asClass(TopologyManagerConfig.class);
|
433
|
28 boolean match = false;
|
|
29 // check cookie
|
|
30 if (host.cookie != null) {
|
434
|
31 if (absCookieTable.containsKey(host.cookie)){
|
|
32 match = true;
|
|
33 host.absName = absCookieTable.get(host.cookie);
|
436
|
34 System.out.println("match");
|
433
|
35 }
|
|
36 }
|
434
|
37
|
466
|
38 if (match){
|
433
|
39 // coming host has ever joined this App
|
|
40 ods.put("reconnectHost", host);
|
515
|
41 if (conf.dynamic) { //dynamic topology
|
|
42 if (conf.type == TopologyType.Tree) {
|
|
43 ods.put("orderHash", "order");
|
|
44 ods.put("newHost", host);
|
|
45 }
|
|
46 } else { // static topology
|
|
47 new SearchHostName();
|
|
48 }
|
433
|
49 } else {
|
517
|
50 host.cookie = null;
|
433
|
51 ods.put("orderHash", "order");
|
|
52 ods.put("newHost", host);
|
|
53 }
|
434
|
54
|
|
55 new CheckComingHost();
|
433
|
56 }
|
|
57
|
|
58 }
|