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.SocketChannel chan  
    protected boolean isClosed  
    protected java.nio.channels.SelectionKey key  
    protected java.util.concurrent.Executor myActor  
    protected java.nio.ByteBuffer readBuf  
    protected java.lang.Thread theExecutingThread
    writes given buffer content.
    protected Promise writePromise  
    protected java.nio.ByteBuffer writingBuffer  
  • Constructor Summary

    Constructors 
    Constructor Description
    AsyncSocketConnection​(java.nio.channels.SelectionKey key, java.nio.channels.SocketChannel chan)  
  • Method Summary

    Modifier and Type Method Description
    boolean canWrite()  
    protected void checkThread()  
    void close()  
    abstract void closed​(java.lang.Throwable ioe)  
    abstract void dataReceived​(java.nio.ByteBuffer buf)  
    protected IPromise directWrite​(java.nio.ByteBuffer buf)  
    boolean isClosed()  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • readBuf

      protected java.nio.ByteBuffer readBuf
    • key

      protected java.nio.channels.SelectionKey key
    • chan

      protected java.nio.channels.SocketChannel chan
    • writePromise

      protected Promise writePromise
    • writingBuffer

      protected java.nio.ByteBuffer writingBuffer
    • isClosed

      protected boolean isClosed
    • myActor

      protected java.util.concurrent.Executor myActor
    • theExecutingThread

      protected java.lang.Thread theExecutingThread
      writes 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

      protected IPromise directWrite​(java.nio.ByteBuffer buf)
    • canWrite

      public boolean canWrite()
    • dataReceived

      public abstract void dataReceived​(java.nio.ByteBuffer buf)
    • isClosed

      public boolean isClosed()