view src/pathfinder/mergetest/channels/SelectionKeySimulator.java @ 161:66e9cebce3fa first_channels

move from pathfinder.simulator.channels.*
author kent
date Tue, 26 Aug 2008 19:46:37 +0900
parents
children
line wrap: on
line source

package pathfinder.mergetest.channels;

public class SelectionKeySimulator<P> {

	public static final int OP_READ = 0x01;
	public static final int OP_ACCEPT = 0x02;
	public static final int OP_WRITE = 0x04;
	
	private int interestOpt;
	private SelectableChannelSimulator<P> channel;
	private Object attachment;

	public SelectionKeySimulator(SelectableChannelSimulator<P> cs, int opt) {
		channel = cs;
		interestOpt = opt;
	}

	public boolean isAble() {
		if ( (interestOpt&OP_READ)!=0 && isReadable() )
			return true;
		else if( (interestOpt&OP_ACCEPT)!=0 && isAcceptable() )
			return true;
		else if( (interestOpt&OP_WRITE)!=0 && isWritable() )
			return true;
		else
			return false;
	}

	public boolean isAcceptable() {
		return channel.isAcceptable();
	}

	public boolean isReadable() {
		return channel.isReadable();
	}
	public boolean isWritable() {
		return channel.isWritable();
	}

	public SelectableChannelSimulator<P> channel() {
		return channel;
	}

	public Object attachment() {
		return attachment;
	}

	public void attach(Object handler) {
		attachment = handler;
	}

}