view rep/channel/ServerChannelSimulator.java @ 203:4c0a94836357 simullator-nio-both-worked

*** empty log message ***
author kono
date Sat, 30 Aug 2008 11:21:43 +0900
parents be219ba8b39c
children e72e0eae1261
line wrap: on
line source

package rep.channel;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.SocketAddress;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.spi.SelectorProvider;

/* シミュレーションの際にコンストラクトされる REPServerSocketChannel の実装  */
public class ServerChannelSimulator<P>extends REPServerSocketChannel<P> {
	protected NetworkSimulator<P> ns;
	//public REPServerSocket<REPSocketChannel<P>> socket;
	protected SocketAddress IP;

	/**  Constructors. 
	 * @throws IOException */
	public ServerChannelSimulator() throws IOException {
		//socket = REPServerSocket.<REPSocketChannel<P>>create();
		ns = NetworkSimulator.<P>singleton();
	}
	
	public void bind(SocketAddress ip){
		IP = ip;
	}

	public REPSocketChannel<P> accept1() /*throws IOException*/ {
		return ns.accept(IP);
	}

	public ServerSocket socket() {
		try {
			return  new REPServerSocket(this);
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}

	

	public SelectionKey register(REPSelector<P> sel, int ops, Object att) throws ClosedChannelException {
		REPSelector<P> selector = sel;
		ns.listen(IP, (SelectorSimulator<P>) selector);
		return selector.register(this, ops, att);
	}

	public boolean isAcceptable() {
		return ns.canAccept(IP);
	}

	@Override
	public Object blockingLock() {
		// TODO Auto-generated method stub
		return null;
	}

	public SelectableChannel configureBlocking(boolean block)
			throws IOException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean isBlocking() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isRegistered() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public SelectionKey keyFor(Selector sel) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public SelectorProvider provider() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public SelectionKey register(Selector sel, int ops, Object att)
			throws ClosedChannelException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int validOps() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	protected void implCloseChannel() throws IOException {
		// TODO Auto-generated method stub
		
	}

}