Class WriteFlusher

    • Constructor Detail

      • WriteFlusher

        protected WriteFlusher​(EndPoint endPoint)
    • Method Detail

      • isCallbackNonBlocking

        public boolean isCallbackNonBlocking()
      • onIncompleteFlush

        protected abstract void onIncompleteFlush()
        Abstract call to be implemented by specific WriteFlushers. It should schedule a call to completeWrite() or onFail(Throwable) when appropriate.
      • write

        public void write​(Callback callback,
                          ByteBuffer... buffers)
                   throws WritePendingException
        Tries to switch state to WRITING. If successful it writes the given buffers to the EndPoint. If state transition fails it'll fail the callback. If not all buffers can be written in one go it creates a new PendingState object to preserve the state and then calls onIncompleteFlush(). The remaining buffers will be written in completeWrite(). If all buffers have been written it calls callback.complete().
        Parameters:
        callback - the callback to call on either failed or complete
        buffers - the buffers to flush to the endpoint
        Throws:
        WritePendingException - if unable to write due to prior pending write
      • completeWrite

        public void completeWrite()
        Complete a write that has not completed and that called onIncompleteFlush() to request a call to this method when a call to EndPoint.flush(ByteBuffer...) is likely to be able to progress. It tries to switch from PENDING to COMPLETING. If state transition fails, then it does nothing as the callback should have been already failed. That's because the only way to switch from PENDING outside this method is onFail(Throwable) or onClose()
      • flush

        protected ByteBuffer[] flush​(ByteBuffer[] buffers)
                              throws IOException
        Flushes the buffers iteratively until no progress is made.
        Parameters:
        buffers - The buffers to flush
        Returns:
        The unflushed buffers, or null if all flushed
        Throws:
        IOException - if unable to flush
      • onFail

        public boolean onFail​(Throwable cause)
        Notify the flusher of a failure
        Parameters:
        cause - The cause of the failure
        Returns:
        true if the flusher passed the failure to a Callback instance
      • onClose

        public void onClose()
      • isInProgress

        public boolean isInProgress()
      • toStateString

        public String toStateString()