Mercurial > hg > RemoteEditor > REPSessionManager
view rep/channel/ChannelSimulator.java @ 225:e173411a2499
*** empty log message ***
author | kent |
---|---|
date | Sun, 31 Aug 2008 13:32:15 +0900 |
parents | 4c0a94836357 |
children | 0498425202a4 |
line wrap: on
line source
package rep.channel; import java.io.IOException; import java.net.SocketAddress; import java.nio.channels.ClosedChannelException; import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; public class ChannelSimulator<P> extends SelectableChannelSimulator<P>{ protected NetworkSimulator<P> ns; /** Constructors. */ public ChannelSimulator(){ super(null); ns = NetworkSimulator.<P>singleton(); } public ChannelSimulator<P> createConjugatedChannel() { ChannelSimulator<P> ret = new ChannelSimulator<P>(); ret.qread=qwrite; ret.qwrite=qread; ret.readSelector=writeSelector; ret.writeSelector=readSelector; return ret; } /** Connecting methods */ // for clients. public boolean connect(SocketAddress ip){ return ns.connect(ip, this); } public ChannelSimulator<P> accept(){ return null; } @Override public boolean isAcceptable() { return false; } @Override public boolean isReadable() { synchronized (qread){ return !qread.isEmpty(); } } @Override public boolean isWritable() { return true; } @Override public SelectableChannel configureBlocking(boolean block) throws IOException { return null; } @SuppressWarnings("unchecked") public SelectionKey keyFor(Selector selector2) { return ((SelectorSimulator) selector2).getKey(this); } @SuppressWarnings("unchecked") @Override public SelectionKey register(Selector sel, int ops, Object att) throws ClosedChannelException { SelectorSimulator<P> selector = (SelectorSimulator<P>) sel; return selector.register(this, ops, att); } public SelectionKey register(REPSelector<P> sel, int ops, Object att) throws ClosedChannelException { return sel.register(this, ops, att); } }