Mercurial > hg > RemoteEditor > REPSessionManager
view rep/channel/REPSocketChannel.java @ 179:763aad2da6b3
*** empty log message ***
author | pin |
---|---|
date | Thu, 28 Aug 2008 22:53:05 +0900 |
parents | 72252e970a8b |
children | 3c82100cdadd |
line wrap: on
line source
package rep.channel; import java.io.IOException; import java.net.Socket; import java.net.SocketAddress; import java.nio.ByteBuffer; import java.nio.channels.ClosedChannelException; import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; import java.nio.channels.SocketChannel; import java.nio.channels.ServerSocketChannel; import java.nio.channels.spi.SelectorProvider; public class REPSocketChannel<P> extends SelectableChannel{ private SocketChannel sc; private REPUnpack<P> unpack; private REPPack<P> pack; public REPSocketChannel(SocketChannel channel) { sc = channel; } public void setUnpack(REPUnpack<P> _unpack){ unpack = _unpack; } public void setPack(REPPack<P> _pack){ pack = _pack; } @Override public Object blockingLock() { return sc.blockingLock(); } @Override public SelectableChannel configureBlocking(boolean block) throws IOException { return sc.configureBlocking(block); } @Override public boolean isBlocking() { return sc.isBlocking(); } @Override public boolean isRegistered() { return sc.isRegistered(); } @Override public SelectionKey keyFor(Selector sel) { return sc.keyFor(sel); } @Override public SelectorProvider provider() { return sc.provider(); } @Override public SelectionKey register(Selector sel, int ops, Object att) throws ClosedChannelException { return sc.register(sel, ops, att); } @Override public int validOps() { return sc.validOps(); } @Override protected void implCloseChannel() throws IOException { sc.close(); } public long read(ByteBuffer header) { // TODO Auto-generated method stub return 0; } public void write(ByteBuffer buffer) throws IOException { // TODO Auto-generated method stub } public boolean finishConnect() { // TODO Auto-generated method stub return false; } public Socket socket() { // TODO Auto-generated method stub return null; } public P read() throws IOException{ return unpack.unpackUConv(sc); } public boolean write(P p){ ByteBuffer bb = pack.packUConv(p); try { while (bb.remaining() > 0 ){ sc.write(bb); } return true; } catch (IOException e) { return false; } } public static <T> REPSocketChannel<T> create() throws IOException { if (REPServerSocketChannel.isSimulation) { return new ChannelSimulator<T>(); } else { return new REPSocketChannel<T>(SocketChannel.open()); } } public boolean connect(SocketAddress semaIP) throws IOException { return sc.connect(semaIP); } }