Mercurial > hg > Database > Alice
annotate src/main/java/alice/topology/manager/IncomingHosts.java @ 435:41bb86275910 dispose
send MD5 "mode -t"
author | sugi |
---|---|
date | Tue, 12 Aug 2014 07:37:17 +0900 |
parents | 4c62f76894c8 |
children | b9fd22d9f6c5 |
rev | line source |
---|---|
401 | 1 package alice.topology.manager; |
2 | |
3 import java.util.HashMap; | |
4 import java.util.LinkedList; | |
5 | |
6 import org.msgpack.type.ValueFactory; | |
7 | |
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 IncomingHosts extends CodeSegment { | |
410 | 15 |
16 HashMap<String, LinkedList<NodeInfo>> topology; | |
17 LinkedList<String> nodeNames; | |
433 | 18 private Receiver host = ids.create(CommandType.TAKE); //HostMessage |
434 | 19 private Receiver absCookieTable = ids.create(CommandType.TAKE); // cookie, AbsName HashMap |
431 | 20 private Receiver cookie = ids.create(CommandType.TAKE); // MD5 |
410 | 21 |
22 public IncomingHosts(HashMap<String, LinkedList<NodeInfo>> topology, | |
23 LinkedList<String> nodeNames) { | |
24 this.topology = topology; | |
25 this.nodeNames = nodeNames; | |
422 | 26 this.host.setKey("host"); |
434 | 27 this.absCookieTable.setKey("absCookieTable"); |
431 | 28 this.cookie.setKey("MD5"); |
410 | 29 } |
401 | 30 |
410 | 31 @Override |
32 public void run() { | |
33 HostMessage host = this.host.asClass(HostMessage.class); | |
431 | 34 @SuppressWarnings("unchecked") |
434 | 35 HashMap<String, String> absCookieTable = this.absCookieTable.asClass(HashMap.class); |
429 | 36 boolean match = false; |
423 | 37 // check cookie |
424
faae3e976cc1
change cookie LinkedLIst Type from String.class to HostMessage.class
sugi
parents:
423
diff
changeset
|
38 if (host.cookie != null) { |
434 | 39 if (absCookieTable.containsKey(host.cookie)){ |
40 match = true; | |
41 System.out.println("cookie is match"); | |
42 host.absName = absCookieTable.get(host.cookie); | |
43 ods.put("reconnectHost", host); | |
44 | |
45 ods.put(this.absCookieTable.key, absCookieTable); | |
46 new SearchHostName(); | |
47 | |
428
93995b7a9a05
change HostMessage field from parentAbsName to remoteAbsName
sugi
parents:
424
diff
changeset
|
48 } |
424
faae3e976cc1
change cookie LinkedLIst Type from String.class to HostMessage.class
sugi
parents:
423
diff
changeset
|
49 } |
423 | 50 |
429 | 51 if (!match) { |
52 System.out.println("new node come"); | |
53 // not have or match cookie | |
54 String nodeName = nodeNames.poll(); | |
55 // Manager connect to Node | |
56 DataSegment.connect(nodeName, "", host.name, host.port); | |
57 ods.put(nodeName, "host", nodeName); | |
58 | |
431 | 59 String cookie = this.cookie.asString(); |
434 | 60 absCookieTable.put(cookie, nodeName); |
61 ods.put(this.absCookieTable.key, absCookieTable); | |
431 | 62 |
429 | 63 ods.put(nodeName, "cookie", cookie); |
64 | |
65 LinkedList<NodeInfo> nodes = topology.get(nodeName); | |
66 for (NodeInfo nodeInfo : nodes) { | |
67 HostMessage newHost = new HostMessage(host.name, host.port, | |
68 nodeInfo.connectionName, nodeInfo.reverseName); | |
69 newHost.absName = nodeName; | |
70 newHost.remoteAbsName = nodeInfo.sourceNodeName; | |
435 | 71 |
429 | 72 ods.put("nodeInfo", newHost); |
73 ods.put(nodeInfo.sourceNodeName, newHost); | |
74 new RecodeTopology(); | |
75 } | |
76 | |
77 if (nodeNames.isEmpty()) { | |
78 // configuration finish | |
79 for (String key : topology.keySet()) { | |
80 ods.put("local", key, ValueFactory.createNilValue()); | |
81 } | |
82 } | |
83 } | |
431 | 84 ods.put("orderHash", "order"); |
429 | 85 new IncomingHosts(topology, nodeNames); |
410 | 86 } |
401 | 87 } |