view src/alice/topology/manager/IncomingHosts.java @ 67:2afbb6404840

off logger for experiment
author kazz <kazz@cr.ie.u-ryukyu.ac.jp>
date Fri, 10 Feb 2012 03:33:29 +0900
parents ca079a730d0b
children d4c7f7b1096b
line wrap: on
line source

package alice.topology.manager;

import java.util.HashMap;
import java.util.LinkedList;

import org.apache.log4j.Logger;

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);
//	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() {
		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");
		}
	}

}