Mercurial > hg > RemoteEditor > REPSessionManager
view rep/channel/REPServerSocketChannel.java @ 217:4deaaaa6354e
*** empty log message ***
author | kono |
---|---|
date | Sun, 31 Aug 2008 00:26:35 +0900 |
parents | 302c4a0afab6 |
children | e173411a2499 |
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.SelectableChannel; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; import java.nio.channels.spi.SelectorProvider; /* * シミュレーションでは inheritance のServerChannelSimulator を生成、 * リアルコミュニケーションでは 自身を生成、内部にもつ ServerSocketChannelを扱う */ public class REPServerSocketChannel<P> extends SelectableChannel { public static boolean isSimulation; private ServerSocketChannel ssc; private REPPack<P> packer; public REPServerSocketChannel() { } 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 static <T> REPServerSocketChannel<T> open(SelectableChannel c,REPPack<T> packer) throws IOException{ assert(!isSimulation); return new REPServerSocketChannel<T>((ServerSocketChannel)c, packer); } public REPServerSocketChannel(ServerSocketChannel open, REPPack<P> packer) { ssc = open; this.packer = packer; REPSocketChannel.addChannel(ssc,this); } public void close1() throws IOException { REPSocketChannel.removeChannel(ssc); ssc.close(); } public REPServerSocketChannel(SelectableChannel channel, REPPack<P> packer) { this.ssc = (ServerSocketChannel)channel; this.packer = packer; REPSocketChannel.addChannel(ssc,this); } public REPSocketChannel<P> accept1() throws IOException { return new REPSocketChannel<P>(ssc.accept(), packer); } public SelectionKey register(REPSelector<P> sel, int ops, Object att) throws ClosedChannelException { assert(!isSimulation); if(sel!=null) return sel.register(ssc, ops, att); else return null; } public SocketChannel accept() throws IOException { return accept1().sc; } public ServerSocket socket() { return ssc.socket(); } public SelectableChannel configureBlocking(boolean block) throws IOException { ssc.configureBlocking(block); return this; } @Override public Object blockingLock() { // 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 } }