view src/alice/topology/node/IncomingConnectionInfo.java @ 31:5c704b9a9a87

add ring script
author kazz <kazz@cr.ie.u-ryukyu.ac.jp>
date Tue, 17 Jan 2012 20:24:46 +0900
parents 98ab26e09a98
children 2bfb796b0fa1
line wrap: on
line source

package alice.topology.node;

import java.io.IOException;

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 IncomingConnectionInfo extends CodeSegment {

	public DataSegmentReceiver hostInfo = new DataSegmentReceiver(ids, CommandType.TAKE);
	private String absName;
	private int count;
	
	public IncomingConnectionInfo(String absName, int count) {
		this.absName = absName;
		this.count = count;
	}

	@Override
	public void run() {
		if (this.hostInfo.val == null) {
			ods.put("local", "configNodeNum", count);
			return;
		}
		MessagePack msgpack = new MessagePack();
		try {
			HostMessage hostInfo = msgpack.convert(this.hostInfo.val, HostMessage.class);
			DataSegment.connect(hostInfo.connectionName, hostInfo.reverseName, hostInfo.name, hostInfo.port);
			//manager.put("reverseKey", ValueFactory.createRawValue(hostInfo.reverseName));
			ods.put(hostInfo.connectionName, "reverseKey", hostInfo.reverseName);
		} catch (IOException e) {
			e.printStackTrace();
		}

		IncomingConnectionInfo cs = new IncomingConnectionInfo(absName, ++count);
		cs.hostInfo.setKey("manager", absName);
	}

}