Package org.nustaq.kontraktor.asyncio
Class AsyncSocketConnection
java.lang.Object
org.nustaq.kontraktor.asyncio.AsyncSocketConnection
- Direct Known Subclasses:
QueuingAsyncSocketConnection
public abstract class AsyncSocketConnection
extends java.lang.Object
Baseclass for handling async io. Its strongly recommended to use QueuingAsyncSocketConnection as this
eases things.
-
Field Summary
Fields Modifier and Type Field Description protected java.nio.channels.SocketChannelchanprotected booleanisClosedprotected java.nio.channels.SelectionKeykeyprotected java.util.concurrent.ExecutormyActorprotected java.nio.ByteBufferreadBufprotected java.lang.ThreadtheExecutingThreadwrites given buffer content.protected PromisewritePromiseprotected java.nio.ByteBufferwritingBuffer -
Constructor Summary
Constructors Constructor Description AsyncSocketConnection(java.nio.channels.SelectionKey key, java.nio.channels.SocketChannel chan) -
Method Summary
Modifier and Type Method Description booleancanWrite()protected voidcheckThread()voidclose()abstract voidclosed(java.lang.Throwable ioe)abstract voiddataReceived(java.nio.ByteBuffer buf)protected IPromisedirectWrite(java.nio.ByteBuffer buf)booleanisClosed()
-
Field Details
-
readBuf
protected java.nio.ByteBuffer readBuf -
key
protected java.nio.channels.SelectionKey key -
chan
protected java.nio.channels.SocketChannel chan -
writePromise
-
writingBuffer
protected java.nio.ByteBuffer writingBuffer -
isClosed
protected boolean isClosed -
myActor
protected java.util.concurrent.Executor myActor -
theExecutingThread
protected java.lang.Thread theExecutingThreadwrites given buffer content. In case of partial write, another write is enqueued internally. once the write is completed, the returned promise is fulfilled. the next write has to wait until the future has completed, else write order might get mixed up. Better use write* methods of QueuingAsyncSocketConnection as these will write to a binary queue which is read+sent behind the scenes in parallel.
-
-
Constructor Details
-
AsyncSocketConnection
public AsyncSocketConnection(java.nio.channels.SelectionKey key, java.nio.channels.SocketChannel chan)
-
-
Method Details
-
closed
public abstract void closed(java.lang.Throwable ioe) -
close
public void close() throws java.io.IOException- Throws:
java.io.IOException
-
checkThread
protected void checkThread() -
directWrite
-
canWrite
public boolean canWrite() -
dataReceived
public abstract void dataReceived(java.nio.ByteBuffer buf) -
isClosed
public boolean isClosed()
-