view src/alice/topology/node/StartTopologyNode.java @ 26:9c6b9e032338

implements TopologyNode
author kazz <kazz@cr.ie.u-ryukyu.ac.jp>
date Tue, 17 Jan 2012 03:11:23 +0900
parents 50c75cb3de60
children f54dcbebde3a
line wrap: on
line source

package alice.topology.node;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

import org.msgpack.MessagePack;

import alice.codesegment.CodeSegment;
import alice.datasegment.DataSegment;
import alice.datasegment.DataSegmentManager;
import alice.topology.HostMessage;

public class StartTopologyNode extends CodeSegment {

	private TopologyNodeConfig conf;
	private Class<CodeSegment> clazz;
	
	public StartTopologyNode(TopologyNodeConfig conf, Class<CodeSegment> clazz) {
		this.conf = conf;
		this.clazz = clazz;
	}
	
	@Override
	public void run() {
		DataSegmentManager manager = DataSegment.connect("topology_manager", conf.managerHostName, conf.managerPort);
		try {
			HostMessage host;
			host = new HostMessage(InetAddress.getLocalHost().getHostName(), conf.localPort);
			MessagePack msgpack = new MessagePack();
			manager.put("host", msgpack.unconvert(host));
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		IncomingAbstractHostName cs = new IncomingAbstractHostName(clazz);
		cs.absName.setKey("local", "host");
	}

}