Mercurial > hg > RemoteEditor > REPSessionManager
view rep/channel/ChannelSimulator.java @ 144:0bf7f8d0f5f7
*** empty log message ***
author | pin |
---|---|
date | Wed, 27 Aug 2008 22:55:43 +0900 |
parents | 785a3e8ea858 |
children | 4cfed12aa3aa |
line wrap: on
line source
package rep.channel; import java.io.IOException; import java.nio.channels.ClosedChannelException; import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; import java.nio.channels.spi.SelectorProvider; public class ChannelSimulator<P> extends SelectableChannelSimulator<P>{ //private BlockingQueue<P> qread; //private BlockingQueue<P> qwrite; //private SelectorSimulator<P> waitingSelector; protected NetworkSimulator<P> ns; /** Constructors. */ public ChannelSimulator(NetworkSimulator<P> _ns){ this(_ns, null); } public ChannelSimulator(NetworkSimulator<P> _ns, SelectorSimulator _selector){ super(null); ns = _ns; //ns = NetworkSimulator.singleton(); //どっちがいい? } public ChannelSimulator<P> createConjugatedChannel() { ChannelSimulator<P> ret = new ChannelSimulator<P>(ns); ret.qread=qwrite; ret.qwrite=qread; ret.readSelector=writeSelector; ret.writeSelector=readSelector; return ret; } /** Connecting methods */ // for clients. public boolean connect(int ip){ return ns.connect(ip, this); } public ChannelSimulator<P> accept(){ return null; } /* return state of the Queue(debug) */ /* public boolean readQisEmpty() { return qread.isEmpty(); } public boolean writeQisEmpty() { return qwrite.isEmpty(); } */ @Override public boolean isAcceptable() { return false; } @Override public boolean isReadable() { synchronized (qread){ return !qread.isEmpty(); } } @Override public boolean isWritable() { return true; } public SelectionKey keyFor(Selector selector2) { return ((SelectorSimulator) selector2).getKey(this); } @Override public Object blockingLock() { // TODO Auto-generated method stub return null; } @Override public SelectableChannel configureBlocking(boolean block) throws IOException { // 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 SelectorProvider provider() { // TODO Auto-generated method stub return null; } @SuppressWarnings("unchecked") @Override public SelectionKey register(Selector sel, int ops, Object att) throws ClosedChannelException { SelectorSimulator selector = (SelectorSimulator) sel; return selector.register(this, ops, att); } public SelectionKey register(REPSelector sel, int ops, Object att) throws ClosedChannelException { REPSelector selector = sel; return selector.register(this, ops, att); } @Override public int validOps() { // TODO Auto-generated method stub return 0; } @Override protected void implCloseChannel() throws IOException { // TODO Auto-generated method stub } }