429
|
1 package alice.topology.manager;
|
|
2
|
|
3 import java.util.HashMap;
|
|
4 import java.util.LinkedList;
|
|
5
|
432
|
6 import org.msgpack.type.ValueFactory;
|
|
7
|
429
|
8 import alice.codesegment.CodeSegment;
|
|
9 import alice.datasegment.CommandType;
|
|
10 import alice.datasegment.DataSegment;
|
|
11 import alice.datasegment.Receiver;
|
|
12 import alice.topology.HostMessage;
|
|
13
|
|
14 public class SearchHostName extends CodeSegment {
|
|
15
|
|
16 private Receiver info = ids.create(CommandType.TAKE); // reconnect NodeInfo
|
|
17 private Receiver info1 = ids.create(CommandType.TAKE); // topology recode (HashMap)
|
432
|
18 private Receiver info2 = ids.create(CommandType.PEEK); // check App running
|
429
|
19
|
|
20 public SearchHostName(){
|
433
|
21 info.setKey("reconnectHost");
|
429
|
22 info1.setKey("topology");
|
432
|
23 info2.setKey("running");
|
429
|
24 }
|
|
25
|
|
26 @Override
|
|
27 public void run() {
|
|
28 HostMessage hostInfo = info.asClass(HostMessage.class);
|
432
|
29 boolean running = info2.asClass(boolean.class);
|
429
|
30 @SuppressWarnings("unchecked")
|
|
31 HashMap<String, LinkedList<HostMessage>> topology = info1.asClass(HashMap.class);
|
|
32
|
|
33 DataSegment.remove(hostInfo.absName);
|
|
34 DataSegment.connect(hostInfo.absName, "", hostInfo.name, hostInfo.port);
|
|
35 ods.put(hostInfo.absName, "host", hostInfo.absName);
|
|
36
|
|
37 // put Host dataSegment on reconnect node
|
|
38 if (topology.containsKey(hostInfo.absName)) {
|
|
39 LinkedList<HostMessage> clist = topology.get(hostInfo.absName);
|
432
|
40 ods.put(hostInfo.absName, "dummy");
|
|
41 if (running){
|
|
42 ods.put(hostInfo.absName, ValueFactory.createNilValue());
|
|
43 }
|
|
44 for (HostMessage node : clist){
|
|
45 ods.put("local" ,hostInfo.absName, node);
|
|
46 System.out.println("put data in "+ hostInfo.absName);
|
|
47 }
|
429
|
48 }
|
|
49
|
|
50 // update topology information
|
|
51 for (LinkedList<HostMessage> list :topology.values()){
|
|
52 for (HostMessage host : list){
|
|
53
|
|
54 // find and update old info
|
|
55 if (hostInfo.absName.equals(host.absName)){
|
|
56 if (!hostInfo.name.equals(host.name) || (hostInfo.port != host.port)){
|
432
|
57 host.name = hostInfo.name;
|
|
58 host.port = hostInfo.port;
|
|
59
|
|
60 ods.put(host.remoteAbsName, host);
|
|
61
|
429
|
62 } else {
|
|
63 // nothing to do ?
|
|
64 }
|
|
65 }
|
|
66 }
|
|
67 }
|
|
68
|
|
69 for (LinkedList<HostMessage> list :topology.values()){
|
|
70 System.out.print(list.get(0).remoteAbsName+" : ");
|
|
71 for (HostMessage host : list){
|
|
72 System.out.print("[ "+host.absName+" "+host.name+" "+host.port+" "+host.connectionName+" "+host.reverseName+" "+host.remoteAbsName+" ]");
|
|
73 }
|
|
74 System.out.println();
|
|
75 }
|
|
76 ods.put("topology", topology);
|
|
77 }
|
|
78
|
|
79 }
|