view src/alice/topology/node/IncomingConnectionInfo.java @ 28:98ab26e09a98

Configuration Manager work and implements reverseKey
author kazz <kazz@cr.ie.u-ryukyu.ac.jp>
date Tue, 17 Jan 2012 08:41:34 +0900
parents f54dcbebde3a
children 5c704b9a9a87
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", ValueFactory.createIntegerValue(count));
			
			return;
		}
		MessagePack msgpack = new MessagePack();
		try {
			HostMessage hostInfo = msgpack.convert(this.hostInfo.val, HostMessage.class);
			DataSegmentManager manager = DataSegment.connect(hostInfo.connectionName, hostInfo.reverseName, hostInfo.name, hostInfo.port);
			manager.put("reverseKey", ValueFactory.createRawValue(hostInfo.reverseName));
		} catch (IOException e) {
			e.printStackTrace();
		}

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

}