view src/alice/topology/manager/IncomingHosts.java @ 90:75aa139d46eb working

minor change
author sugi
date Tue, 05 Jun 2012 00:26:13 +0900
parents d4c7f7b1096b
children b5daccf36104
line wrap: on
line source

package alice.topology.manager;

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);
	
	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);
		String nodeName = nodeNames.poll();
		// Manager connect to Node
		DataSegment.connect(nodeName, "", host.name, host.port);
		ods.put(nodeName, "host", nodeName);
		LinkedList<NodeInfo> nodes = topology.get(nodeName);
		for (NodeInfo nodeInfo : nodes) {
			HostMessage newHost = new HostMessage(host.name, host.port, nodeInfo.connectionName, nodeInfo.reverseName);
			ods.put("local", nodeInfo.sourceNodeName, newHost);
		}
		
		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");
		}
	}

}