Mercurial > hg > RemoteEditor > REPSessionManager
view rep/channel/REPServerSocketChannel.java @ 190:63701e2a2fe8
*** empty log message ***
author | kent |
---|---|
date | Fri, 29 Aug 2008 18:51:37 +0900 |
parents | b9855078a070 |
children | be219ba8b39c |
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; private REPPack<P> packer; protected REPServerSocketChannel(SelectorProvider provider) { super(provider); } public REPServerSocketChannel(ServerSocketChannel channel, REPPack<P> _packer){ super(SelectorProvider.provider()); ss = channel; packer = _packer; } public REPServerSocketChannel() { super(null); } public static <T> REPServerSocketChannel<T> open(REPPack<T> packer) throws IOException{ if(isSimulation){ return new ServerChannelSimulator<T>(); }else{ return new REPServerSocketChannel<T>(ServerSocketChannel.open(), packer); } } public REPSocketChannel<P> accept1() throws IOException { return new REPSocketChannel<P>(accept(), packer); } @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); } public SelectionKey register(REPSelector sel, int ops, Object att) throws ClosedChannelException { assert(!isSimulation); REPSelector selector = sel; if(sel!=null) return selector.register(this, ops, att); else return null; } @Override public SocketChannel accept() throws IOException { return null;//(SocketChannel) accept1(); } }