Mercurial > hg > Members > tatsuki > Alice
diff src/alice/topology/manager/IncomingHosts.java @ 27:f54dcbebde3a
topology manager work!
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 17 Jan 2012 03:52:39 +0900 |
parents | src/topology/manager/IncomingHosts.java@9c6b9e032338 |
children | 98ab26e09a98 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/alice/topology/manager/IncomingHosts.java Tue Jan 17 03:52:39 2012 +0900 @@ -0,0 +1,59 @@ +package alice.topology.manager; + +import java.io.IOException; +import java.util.HashMap; +import java.util.LinkedList; + +import org.apache.log4j.Logger; +import org.msgpack.MessagePack; +import org.msgpack.type.ValueFactory; + +import alice.codesegment.CodeSegment; +import alice.datasegment.CommandType; +import alice.datasegment.DataSegment; +import alice.datasegment.DataSegmentManager; +import alice.datasegment.DataSegmentReceiver; +import alice.topology.HostMessage; + +public class IncomingHosts extends CodeSegment { + + HashMap<String, LinkedList<NodeInfo>> topology; + LinkedList<String> nodeNames; + DataSegmentReceiver host = new DataSegmentReceiver(ids, CommandType.TAKE); + Logger logger = Logger.getLogger(IncomingHosts.class); + + public IncomingHosts(HashMap<String, LinkedList<NodeInfo>> topology, LinkedList<String> nodeNames) { + this.topology = topology; + this.nodeNames = nodeNames; + } + + @Override + public void run() { + MessagePack msgpack = new MessagePack(); + try { + HostMessage host = msgpack.convert(this.host.val, HostMessage.class); + String nodeName = nodeNames.poll(); + DataSegmentManager manager = DataSegment.connect(nodeName, host.name, host.port); + manager.put("host", ValueFactory.createRawValue(nodeName)); + LinkedList<NodeInfo> nodes = topology.get(nodeName); + for (NodeInfo nodeInfo : nodes) { + HostMessage newHost = new HostMessage(host.name, host.port, nodeInfo.connectionName); + ods.put("local", nodeInfo.sourceNodeName, msgpack.unconvert(newHost)); + } + } catch (IOException e) { + logger.error("HostMessage format error"); + e.printStackTrace(); + } + + if (nodeNames.isEmpty()) { + // configuration finish + for (String key : topology.keySet()) { + ods.put("local", key, ValueFactory.createNilValue()); + } + } else { + IncomingHosts cs = new IncomingHosts(topology, nodeNames); + cs.host.setKey("local", "host"); + } + } + +}