annotate src/main/java/alice/topology/manager/IncomingHosts.java @ 557:1a860019b2fe dispose

add ip to HostMessage.class
author Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
date Fri, 20 Nov 2015 17:57:55 +0900
parents 268b1280dc18
children 0259a8aba18c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
401
91e1b063a89f haven't to remove manager package
sugi
parents:
diff changeset
1 package alice.topology.manager;
91e1b063a89f haven't to remove manager package
sugi
parents:
diff changeset
2
557
1a860019b2fe add ip to HostMessage.class
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents: 466
diff changeset
3 import java.net.InetAddress;
1a860019b2fe add ip to HostMessage.class
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents: 466
diff changeset
4 import java.net.UnknownHostException;
401
91e1b063a89f haven't to remove manager package
sugi
parents:
diff changeset
5 import java.util.HashMap;
91e1b063a89f haven't to remove manager package
sugi
parents:
diff changeset
6 import java.util.LinkedList;
91e1b063a89f haven't to remove manager package
sugi
parents:
diff changeset
7
91e1b063a89f haven't to remove manager package
sugi
parents:
diff changeset
8 import org.msgpack.type.ValueFactory;
91e1b063a89f haven't to remove manager package
sugi
parents:
diff changeset
9
91e1b063a89f haven't to remove manager package
sugi
parents:
diff changeset
10 import alice.codesegment.CodeSegment;
91e1b063a89f haven't to remove manager package
sugi
parents:
diff changeset
11 import alice.datasegment.CommandType;
91e1b063a89f haven't to remove manager package
sugi
parents:
diff changeset
12 import alice.datasegment.DataSegment;
91e1b063a89f haven't to remove manager package
sugi
parents:
diff changeset
13 import alice.datasegment.Receiver;
91e1b063a89f haven't to remove manager package
sugi
parents:
diff changeset
14 import alice.topology.HostMessage;
91e1b063a89f haven't to remove manager package
sugi
parents:
diff changeset
15
91e1b063a89f haven't to remove manager package
sugi
parents:
diff changeset
16 public class IncomingHosts extends CodeSegment {
410
74e13553e3e3 change call do setKey in constractor
tatsuki
parents: 401
diff changeset
17
437
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
18 private Receiver topology = ids.create(CommandType.TAKE); // Topology from parse file
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
19 private Receiver nodeNames = ids.create(CommandType.TAKE); // nodeName list
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
20 private Receiver host = ids.create(CommandType.TAKE); // new coming host info
434
4c62f76894c8 refactoring
sugi
parents: 433
diff changeset
21 private Receiver absCookieTable = ids.create(CommandType.TAKE); // cookie, AbsName HashMap
437
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
22 private Receiver cookie = ids.create(CommandType.TAKE); // MD5
410
74e13553e3e3 change call do setKey in constractor
tatsuki
parents: 401
diff changeset
23
437
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
24 public IncomingHosts() {
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
25 this.topology.setKey("resultParse");
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
26 this.nodeNames.setKey("nodeNames");
438
c973f7ee7c91 refactoring
sugi
parents: 437
diff changeset
27 this.host.setKey("newHost");
434
4c62f76894c8 refactoring
sugi
parents: 433
diff changeset
28 this.absCookieTable.setKey("absCookieTable");
431
0239c1633012 add CodeSegment for creating MD5
sugi
parents: 430
diff changeset
29 this.cookie.setKey("MD5");
410
74e13553e3e3 change call do setKey in constractor
tatsuki
parents: 401
diff changeset
30 }
401
91e1b063a89f haven't to remove manager package
sugi
parents:
diff changeset
31
410
74e13553e3e3 change call do setKey in constractor
tatsuki
parents: 401
diff changeset
32 @Override
74e13553e3e3 change call do setKey in constractor
tatsuki
parents: 401
diff changeset
33 public void run() {
74e13553e3e3 change call do setKey in constractor
tatsuki
parents: 401
diff changeset
34 HostMessage host = this.host.asClass(HostMessage.class);
431
0239c1633012 add CodeSegment for creating MD5
sugi
parents: 430
diff changeset
35 @SuppressWarnings("unchecked")
434
4c62f76894c8 refactoring
sugi
parents: 433
diff changeset
36 HashMap<String, String> absCookieTable = this.absCookieTable.asClass(HashMap.class);
437
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
37 @SuppressWarnings("unchecked")
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
38 HashMap<String, LinkedList<NodeInfo>> topology = this.topology.asClass(HashMap.class);
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
39 @SuppressWarnings("unchecked")
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
40 LinkedList<String> nodeNames = this.nodeNames.asClass(LinkedList.class);
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
41
466
268b1280dc18 remove debug message
sugi
parents: 438
diff changeset
42 // not have or match cookie
437
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
43 String nodeName = nodeNames.poll();
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
44 // Manager connect to Node
557
1a860019b2fe add ip to HostMessage.class
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents: 466
diff changeset
45 DataSegment.connect(nodeName, "", host.ip, host.port);
437
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
46 ods.put(nodeName, "host", nodeName);
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
47
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
48 String cookie = this.cookie.asString();
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
49 absCookieTable.put(cookie, nodeName);
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
50 ods.put(this.absCookieTable.key, absCookieTable);
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
51
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
52 ods.put(nodeName, "cookie", cookie);
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
53
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
54 LinkedList<NodeInfo> nodes = topology.get(nodeName);
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
55 for (NodeInfo nodeInfo : nodes) {
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
56 HostMessage newHost = new HostMessage(host.name, host.port,
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
57 nodeInfo.connectionName, nodeInfo.reverseName);
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
58 newHost.absName = nodeName;
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
59 newHost.remoteAbsName = nodeInfo.sourceNodeName;
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
60
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
61 ods.put("nodeInfo", newHost);
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
62 ods.put(nodeInfo.sourceNodeName, newHost);
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
63 new RecodeTopology();
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
64 }
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
65
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
66 if (nodeNames.isEmpty()) {
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
67 // configuration finish
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
68 for (String key : topology.keySet()) {
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
69 ods.put("local", key, ValueFactory.createNilValue());
428
93995b7a9a05 change HostMessage field from parentAbsName to remoteAbsName
sugi
parents: 424
diff changeset
70 }
424
faae3e976cc1 change cookie LinkedLIst Type from String.class to HostMessage.class
sugi
parents: 423
diff changeset
71 }
466
268b1280dc18 remove debug message
sugi
parents: 438
diff changeset
72
437
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
73 ods.put(this.nodeNames.key, nodeNames);
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
74 ods.put(this.topology.key, topology);
466
268b1280dc18 remove debug message
sugi
parents: 438
diff changeset
75
437
b9fd22d9f6c5 refactoring IncomingHosts.java
sugi
parents: 435
diff changeset
76 new IncomingHosts();
410
74e13553e3e3 change call do setKey in constractor
tatsuki
parents: 401
diff changeset
77 }
401
91e1b063a89f haven't to remove manager package
sugi
parents:
diff changeset
78 }