Mercurial > hg > RemoteEditor > REPSessionManager
view rep/channel/REPSelectionKey.java @ 437:2c00fa39dd84
minor fix
author | one |
---|---|
date | Fri, 03 Sep 2010 10:22:39 +0900 |
parents | c5be84d53c7f |
children |
line wrap: on
line source
package rep.channel; import java.io.IOException; 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; public class REPSelectionKey<P> extends SelectionKey { SelectionKey key; private REPSelector<P> selector; public REPSelectionKey() { } public REPSelectionKey(SelectionKey key,REPSelector<P>s) { this.key = key; this.selector = s; attach(key.attachment()); } @Override public void cancel() { key.cancel(); } @Override public SelectableChannel channel() { if (REPServerSocketChannel.isSimulation) return key.channel(); SelectableChannel sc = key.channel(); SelectableChannel rsc = REPSocketChannel.channels.get(sc); return rsc; } @SuppressWarnings("unchecked") public REPSocketChannel<P> channel1() { assert (!REPServerSocketChannel.isSimulation); SelectableChannel sc = key.channel(); REPSocketChannel<P> rsc = (REPSocketChannel<P>) REPSocketChannel.channels.get(sc); return rsc; } @SuppressWarnings("unchecked") public REPServerSocketChannel<P> serverSocketChannel() { assert (!REPServerSocketChannel.isSimulation); SelectableChannel sc = key.channel(); REPServerSocketChannel<P> rsc = (REPServerSocketChannel<P>) REPSocketChannel.channels.get(sc); return rsc; } @Override public int interestOps() { return key.interestOps(); } @Override public SelectionKey interestOps(int ops) { return key.interestOps(ops); } @Override public boolean isValid() { return key.isValid(); } @Override public int readyOps() { return key.readyOps(); } @Override public Selector selector() { return selector; } public REPSocketChannel<P> accept(REPPack<P> pack) throws IOException { assert(!REPServerSocketChannel.isSimulation); if (!key.isAcceptable()) throw new IOException(); ServerSocketChannel ssc = (ServerSocketChannel)key.channel(); if (ssc==null) return null; SocketChannel ss = (SocketChannel)ssc.accept(); //System.err.println("Accept in SelectionKey "+ss); if (ss==null) return null; return new REPSocketChannel<P>(ss, pack); } }