Mercurial > hg > Members > tatsuki > Alice
view src/alice/topology/manager/IncomingHosts.java @ 268:709936c00c89
creating reconnect manager
author | sugi |
---|---|
date | Sun, 18 Aug 2013 02:13:52 +0900 |
parents | c0712e0b0a24 |
children | 3667ab045530 |
line wrap: on
line source
package alice.topology.manager; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; import org.msgpack.type.ValueFactory; import alice.codesegment.CodeSegment; import alice.datasegment.CommandType; import alice.datasegment.DataSegment; import alice.datasegment.Receiver; import alice.topology.HostMessage; public class IncomingHosts extends CodeSegment { HashMap<String, LinkedList<NodeInfo>> topology; LinkedList<String> nodeNames; Receiver host = ids.create(CommandType.TAKE); Receiver connection = ids.create(CommandType.TAKE); public IncomingHosts(HashMap<String, LinkedList<NodeInfo>> topology, LinkedList<String> nodeNames) { this.topology = topology; this.nodeNames = nodeNames; } @Override public void run() { HostMessage host = this.host.asClass(HostMessage.class); @SuppressWarnings("unchecked") HashMap<String, ArrayList<HostMessage>> connectionList = this.connection.asClass(HashMap.class); String nodeName = nodeNames.poll(); // Manager connect to Node // this connection must disconnect DataSegment.connect(nodeName, "", host.name, host.port); System.out.println(nodeName); ods.put(nodeName, "host", nodeName); LinkedList<NodeInfo> nodes = topology.get(nodeName); ArrayList<HostMessage> list; for (NodeInfo nodeInfo : nodes) { //System.out.println(host.name+" "+host.port+" "+nodeInfo.connectionName+" "+ nodeInfo.reverseName+" "+nodeInfo.sourceNodeName); HostMessage newHost = new HostMessage(host.name, host.port, nodeInfo.connectionName, nodeInfo.reverseName); ods.put("local", nodeInfo.sourceNodeName, newHost); if (connectionList.containsKey(nodeInfo.sourceNodeName)){ list = connectionList.get(nodeInfo.sourceNodeName); } else { list = new ArrayList<HostMessage>(); connectionList.put(nodeInfo.sourceNodeName, list); } list.add(newHost); } ods.update("local", "connection", connectionList); 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"); cs.connection.setKey("local", "connection"); } // for Debug if (connectionList.containsKey("node0")){ ArrayList<HostMessage> maplist = connectionList.get("node0"); for (HostMessage i : maplist){ System.out.println(i.name+" "+i.port+" "+i.connectionName+" "+i.reverseName); } } } }