annotate src/alice/topology/manager/IncomingHosts.java @ 33:20c67f673224

change name of DataSegmentReceiver
author kazz <kazz@cr.ie.u-ryukyu.ac.jp>
date Wed, 18 Jan 2012 01:34:23 +0900
parents 2bfb796b0fa1
children ca079a730d0b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27
f54dcbebde3a topology manager work!
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 26
diff changeset
1 package alice.topology.manager;
22
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 import java.io.IOException;
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 import java.util.HashMap;
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 import java.util.LinkedList;
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 import org.apache.log4j.Logger;
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 import org.msgpack.MessagePack;
23
54bf607118ae change method to create RemoteDSM
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 22
diff changeset
9 import org.msgpack.type.ValueFactory;
22
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 import alice.codesegment.CodeSegment;
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 import alice.datasegment.CommandType;
23
54bf607118ae change method to create RemoteDSM
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 22
diff changeset
13 import alice.datasegment.DataSegment;
54bf607118ae change method to create RemoteDSM
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 22
diff changeset
14 import alice.datasegment.DataSegmentManager;
33
20c67f673224 change name of DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
15 import alice.datasegment.Receiver;
22
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 import alice.topology.HostMessage;
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 public class IncomingHosts extends CodeSegment {
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
24
ebd91e607b63 implements TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
20 HashMap<String, LinkedList<NodeInfo>> topology;
22
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 LinkedList<String> nodeNames;
33
20c67f673224 change name of DataSegmentReceiver
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
22 Receiver host = ids.create(CommandType.TAKE);
22
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 Logger logger = Logger.getLogger(IncomingHosts.class);
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
24
ebd91e607b63 implements TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
25 public IncomingHosts(HashMap<String, LinkedList<NodeInfo>> topology, LinkedList<String> nodeNames) {
22
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 this.topology = topology;
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 this.nodeNames = nodeNames;
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 }
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 @Override
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 public void run() {
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 MessagePack msgpack = new MessagePack();
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 try {
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 HostMessage host = msgpack.convert(this.host.val, HostMessage.class);
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 String nodeName = nodeNames.poll();
31
5c704b9a9a87 add ring script
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 28
diff changeset
36 // Manager connect to Node
28
98ab26e09a98 Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
37 DataSegmentManager manager = DataSegment.connect(nodeName, "", host.name, host.port);
23
54bf607118ae change method to create RemoteDSM
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 22
diff changeset
38 manager.put("host", ValueFactory.createRawValue(nodeName));
24
ebd91e607b63 implements TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
39 LinkedList<NodeInfo> nodes = topology.get(nodeName);
ebd91e607b63 implements TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
40 for (NodeInfo nodeInfo : nodes) {
28
98ab26e09a98 Configuration Manager work and implements reverseKey
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 27
diff changeset
41 HostMessage newHost = new HostMessage(host.name, host.port, nodeInfo.connectionName, nodeInfo.reverseName);
24
ebd91e607b63 implements TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
42 ods.put("local", nodeInfo.sourceNodeName, msgpack.unconvert(newHost));
ebd91e607b63 implements TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 23
diff changeset
43 }
22
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 } catch (IOException e) {
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 logger.error("HostMessage format error");
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 e.printStackTrace();
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 }
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48
26
9c6b9e032338 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
49 if (nodeNames.isEmpty()) {
9c6b9e032338 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
50 // configuration finish
9c6b9e032338 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
51 for (String key : topology.keySet()) {
9c6b9e032338 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
52 ods.put("local", key, ValueFactory.createNilValue());
9c6b9e032338 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
53 }
9c6b9e032338 implements TopologyNode
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents: 25
diff changeset
54 } else {
22
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 IncomingHosts cs = new IncomingHosts(topology, nodeNames);
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 cs.host.setKey("local", "host");
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 }
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 }
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59
2ca2d961a8d2 implements outline of TopologyManager
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 }