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