Mercurial > hg > RemoteEditor > REPSessionManager
view rep/channel/ServerChannelSimulator.java @ 175:5653cf8e3c8b
*** empty log message ***
author | kent |
---|---|
date | Thu, 28 Aug 2008 21:22:07 +0900 |
parents | 9bb6bbb08ad7 |
children | be219ba8b39c |
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.SelectionKey; import java.nio.channels.SocketChannel; /* シミュレーションの際にコンストラクトされる 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); } @Override public ServerSocket socket() { try { return new REPServerSocket(this); } catch (IOException e) { e.printStackTrace(); return null; } } @Override protected void implCloseSelectableChannel() throws IOException { return; } @Override protected void implConfigureBlocking(boolean block) throws IOException { return; } @Override public SocketChannel accept() throws IOException { // TODO Auto-generated method stub return null; } public SelectionKey register(REPSelector sel, int ops, Object att) throws ClosedChannelException { REPSelector selector = sel; ns.listen(IP, (SelectorSimulator) selector); return selector.register(this, ops, att); } public boolean isAcceptable() { return ns.canAccept(IP); } }