view rep/channel/REPServerSocketChannel.java @ 168:4ed6393ec68e

*** empty log message ***
author kono
date Thu, 28 Aug 2008 18:54:01 +0900
parents 9bb6bbb08ad7
children eb89a73976fa
line wrap: on
line source

package rep.channel;

import java.io.IOException;
import java.net.ServerSocket;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.SelectionKey;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.channels.spi.SelectorProvider;

/* 
 * シミュレーションでは inheritance のServerChannelSimulator を生成、
 * リアルコミュニケーションでは 自身を生成、内部にもつ ServerSocketChannelを扱う
 */
public class REPServerSocketChannel<P> extends ServerSocketChannel{

	public static boolean isSimulation;
	private ServerSocketChannel ss;
	
	protected REPServerSocketChannel(SelectorProvider provider) {
		super(provider);
		
	}
	
	public REPServerSocketChannel(ServerSocketChannel channel){
		super(null);
		ss = channel;
	}

	public REPServerSocketChannel() {
		super(null);
		
	}

	public static <T> REPServerSocketChannel<T> open() throws IOException{
		if(isSimulation){
			return new ServerChannelSimulator<T>();
		}else{
			return new REPServerSocketChannel<T>(ServerSocketChannel.open());
		}
	}

	public REPSocketChannel<P> accept1() throws IOException {
		return new REPSocketChannel<P>(ss.accept());
	}

	@Override
	public ServerSocket socket() {
		return ss.socket();
	}

	@Override
	protected void implCloseSelectableChannel() throws IOException {
		ss.close();
	}

	@Override
	protected void implConfigureBlocking(boolean block) throws IOException {
		ss.configureBlocking(block);
	}

	@Override
	public SocketChannel accept() throws IOException {
		// TODO Auto-generated method stub
		return null;
	}
	

	public SelectionKey register(REPSelector sel, int ops, Object att) throws ClosedChannelException {
		assert(!isSimulation);
		REPSelector selector = sel;
		return selector.register(ss, ops, att);
	}

}