Mercurial > hg > RemoteEditor > REPSessionManager
view rep/channel/SelectionKeySimulator.java @ 144:0bf7f8d0f5f7
*** empty log message ***
author | pin |
---|---|
date | Wed, 27 Aug 2008 22:55:43 +0900 |
parents | 785a3e8ea858 |
children | 72252e970a8b |
line wrap: on
line source
package rep.channel; import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; public class SelectionKeySimulator<P> extends SelectionKey{ private int interestOpt; private SelectableChannel channel; private int ready; public Selector selector; public SelectionKeySimulator(SelectableChannel cs, int opt, Selector _selector) { channel = cs; interestOpt = opt; selector = _selector; } public boolean isAble() { if ( (interestOpt&OP_READ)!=0 && isReadable() ) return true; else if( (interestOpt&OP_ACCEPT)!=0 && isAcceptable() ) return true; else if( (interestOpt&OP_WRITE)!=0 && isWritable() ) return true; else return false; } public void setFlag() { SelectableChannelSimulator<?> scs = (SelectableChannelSimulator<?>) channel; ready = 0; if(scs.isAcceptable()) ready |= OP_ACCEPT; if(scs.isReadable()) ready |= OP_READ; if(scs.isWritable()) ready |= OP_WRITE; } public SelectableChannel channel() { return channel; } @Override public void cancel() { System.err.println("cancel is not implemented yet."); //selector. } @Override public int interestOps() { return interestOpt; } @Override public SelectionKey interestOps(int ops) { interestOpt = ops; return this; } @Override public boolean isValid() { return true; } @Override public int readyOps() { return ready; } @Override public Selector selector() { return selector; } }