annotate src/main/java/alice/topology/manager/SearchHostName.java @ 433:e565d481c52e dispose

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