comparison src/main/java/alice/topology/manager/IncomingHosts.java @ 345:8f71c3e6f11d

Change directory structure Maven standard
author sugi
date Wed, 16 Apr 2014 18:26:07 +0900
parents
children
comparison
equal deleted inserted replaced
344:9f97ec18f8c5 345:8f71c3e6f11d
1 package alice.topology.manager;
2
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.LinkedList;
6
7 import org.msgpack.type.ValueFactory;
8
9 import alice.codesegment.CodeSegment;
10 import alice.datasegment.CommandType;
11 import alice.datasegment.DataSegment;
12 import alice.datasegment.Receiver;
13 import alice.topology.HostMessage;
14
15 public class IncomingHosts extends CodeSegment {
16
17 HashMap<String, LinkedList<NodeInfo>> topology;
18 LinkedList<String> nodeNames;
19 Receiver host = ids.create(CommandType.TAKE);
20 Receiver connection = ids.create(CommandType.TAKE);
21
22 public IncomingHosts(HashMap<String, LinkedList<NodeInfo>> topology, LinkedList<String> nodeNames) {
23 this.topology = topology;
24 this.nodeNames = nodeNames;
25 }
26
27 @Override
28 public void run() {
29 HostMessage host = this.host.asClass(HostMessage.class);
30 @SuppressWarnings("unchecked")
31 HashMap<String, ArrayList<HostMessage>> connectionList = this.connection.asClass(HashMap.class);
32
33 String nodeName = nodeNames.poll();
34 // Manager connect to Node
35
36 DataSegment.connect(nodeName, "", host.name, host.port, host.reconnectFlag);
37 ods.put(nodeName, "host", nodeName);
38 LinkedList<NodeInfo> nodes = topology.get(nodeName);
39 ArrayList<HostMessage> list;
40 for (NodeInfo nodeInfo : nodes) {
41 HostMessage newHost = new HostMessage(host.name, host.port, nodeInfo.connectionName, nodeInfo.reverseName);
42 ods.put("local", nodeInfo.sourceNodeName, newHost);
43
44 if (connectionList.containsKey(nodeInfo.sourceNodeName)){
45 list = connectionList.get(nodeInfo.sourceNodeName);
46 } else {
47 list = new ArrayList<HostMessage>();
48 connectionList.put(nodeInfo.sourceNodeName, list);
49
50 }
51 list.add(newHost);
52 }
53 ods.update("local", "connection", connectionList);
54
55 if (nodeNames.isEmpty()) {
56 // configuration finish
57 for (String key : topology.keySet()) {
58 ods.put("local", key, ValueFactory.createNilValue());
59 }
60 } else {
61 IncomingHosts cs = new IncomingHosts(topology, nodeNames);
62 cs.host.setKey("local", "host");
63 cs.connection.setKey("local", "connection");
64 }
65 }
66
67 }