Class AbstractNIOAsyncQueueWriter

    • Field Detail

      • maxPendingBytes

        protected volatile int maxPendingBytes
      • maxWriteReentrants

        protected volatile int maxWriteReentrants
    • Constructor Detail

      • AbstractNIOAsyncQueueWriter

        public AbstractNIOAsyncQueueWriter​(NIOTransport transport)
    • Method Detail

      • canWrite

        @Deprecated
        public boolean canWrite​(Connection<java.net.SocketAddress> connection,
                                int size)
        Deprecated.
        Specified by:
        canWrite in interface AsyncQueueWriter<java.net.SocketAddress>
        Parameters:
        connection - the Connection to test whether or not the specified number of bytes can be written to.
        size - number of bytes to write.
        Returns:
        true if the queue has not exceeded it's maximum size in bytes of pending writes, otherwise false
      • canWrite

        public boolean canWrite​(Connection<java.net.SocketAddress> connection)
        Description copied from interface: Writer
        Return true if the connection has not exceeded it's maximum size in bytes of pending writes, otherwise false.
        Specified by:
        canWrite in interface Writer<java.net.SocketAddress>
        Parameters:
        connection - the Connection to test whether or not the specified number of bytes can be written to.
        Returns:
        true if the connection has not exceeded it's maximum size in bytes of pending writes, otherwise false
      • notifyWritePossible

        @Deprecated
        public void notifyWritePossible​(Connection<java.net.SocketAddress> connection,
                                        WriteHandler writeHandler,
                                        int size)
        Deprecated.
        Registers WriteHandler, which will be notified ones the Connection is able to accept more bytes to be written. Note: using this method from different threads simultaneously may lead to quick situation changes, so at time WriteHandler is called - the queue may become busy again.
        Specified by:
        notifyWritePossible in interface AsyncQueueWriter<java.net.SocketAddress>
        Parameters:
        connection - Connection
        writeHandler - WriteHandler to be notified.
        size - number of bytes queue has to be able to accept before notifying WriteHandler.
      • notifyWritePossible

        public void notifyWritePossible​(Connection<java.net.SocketAddress> connection,
                                        WriteHandler writeHandler)
        Description copied from interface: Writer
        Registers WriteHandler, which will be notified ones at least one byte can be written. This method call is equivalent to call notifyWritePossible(connection, writeHandler, 1); Note: using this method from different threads simultaneously may lead to quick situation changes, so at time WriteHandler is called - the queue may become busy again.
        Specified by:
        notifyWritePossible in interface Writer<java.net.SocketAddress>
        Parameters:
        connection - Connection
        writeHandler - WriteHandler to be notified.
      • setMaxPendingBytesPerConnection

        public void setMaxPendingBytesPerConnection​(int maxPendingBytes)
        Configures the maximum number of bytes pending to be written for a particular Connection.
        Specified by:
        setMaxPendingBytesPerConnection in interface AsyncQueueWriter<java.net.SocketAddress>
        Parameters:
        maxPendingBytes - maximum number of bytes that may be pending to be written to a particular Connection.
      • getMaxPendingBytesPerConnection

        public int getMaxPendingBytesPerConnection()
        Specified by:
        getMaxPendingBytesPerConnection in interface AsyncQueueWriter<java.net.SocketAddress>
        Returns:
        the maximum number of bytes that may be pending to be written to a particular Connection. By default, this will be four times the size of the Socket send buffer size.
      • isAllowDirectWrite

        public boolean isAllowDirectWrite()
        Returns true, if async write queue is allowed to write buffer directly during write(...) method call, w/o adding buffer to the queue, or false otherwise.
        Specified by:
        isAllowDirectWrite in interface AsyncQueueWriter<java.net.SocketAddress>
        Returns:
        true, if async write queue is allowed to write buffer directly during write(...) method call, w/o adding buffer to the queue, or false otherwise.
      • setAllowDirectWrite

        public void setAllowDirectWrite​(boolean isAllowDirectWrite)
        Set true, if async write queue is allowed to write buffer directly during write(...) method call, w/o adding buffer to the queue, or false otherwise.
        Specified by:
        setAllowDirectWrite in interface AsyncQueueWriter<java.net.SocketAddress>
        Parameters:
        isAllowDirectWrite - true, if async write queue is allowed to write buffer directly during write(...) method call, w/o adding buffer to the queue, or false otherwise.
      • isReady

        public final boolean isReady​(Connection connection)
        Checks whether there is ready data in AsyncQueue, associated with the Connection.
        Specified by:
        isReady in interface AsyncQueue
        Parameters:
        connection - Connection
        Returns:
        true, if there is ready data, or false otherwise.
      • onClose

        public void onClose​(Connection connection)
        Callback method, which is called, when Connection has been closed, to let processor release a connection associated resources.
        Specified by:
        onClose in interface AsyncQueue
        Parameters:
        connection - Connection
      • close

        public final void close()
        Close AsyncQueueProcessor and release associated resources
        Specified by:
        close in interface AsyncQueue
      • onReadyToWrite

        protected abstract void onReadyToWrite​(NIOConnection connection)
                                        throws java.io.IOException
        Throws:
        java.io.IOException