Class AbstractCoalescingBufferQueue

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractCoalescingBufferQueue​(int initSize)
      Create a new instance.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(io.netty5.buffer.Buffer buf)
      Add a buffer to the end of the queue.
      void add​(io.netty5.buffer.Buffer buf, io.netty5.util.concurrent.FutureListener<Void> listener)
      Add a buffer to the end of the queue and associate a listener with it that should be completed when all the buffers bytes have been consumed from the queue and written.
      void add​(io.netty5.buffer.Buffer buf, io.netty5.util.concurrent.Promise<Void> promise)
      Add a buffer to the end of the queue and associate a promise with it that should be completed when all the buffer's bytes have been consumed from the queue and written.
      void addFirst​(io.netty5.buffer.Buffer buf, io.netty5.util.concurrent.Promise<Void> promise)
      Add a buffer to the front of the queue and associate a promise with it that should be completed when all the buffer's bytes have been consumed from the queue and written.
      protected abstract io.netty5.buffer.Buffer compose​(io.netty5.buffer.BufferAllocator alloc, io.netty5.buffer.Buffer cumulation, io.netty5.buffer.Buffer next)
      Calculate the result of current + next.
      protected io.netty5.buffer.Buffer composeFirst​(io.netty5.buffer.BufferAllocator allocator, io.netty5.buffer.Buffer first)
      Calculate the first Buffer which will be used in subsequent calls to compose(BufferAllocator, Buffer, Buffer).
      protected io.netty5.buffer.Buffer composeIntoComposite​(io.netty5.buffer.BufferAllocator alloc, io.netty5.buffer.Buffer cumulation, io.netty5.buffer.Buffer next)
      Compose cumulation and next into a new CompositeBuffer.
      protected io.netty5.buffer.Buffer copyAndCompose​(io.netty5.buffer.BufferAllocator alloc, io.netty5.buffer.Buffer cumulation, io.netty5.buffer.Buffer next, int minIncrement)
      Compose cumulation and next into a new Buffer suitable for IO.
      void copyTo​(AbstractCoalescingBufferQueue dest)
      Copy all pending entries in this queue into the destination queue.
      boolean isEmpty()
      Are there pending buffers in the queue.
      int readableBytes()
      The number of readable bytes.
      void releaseAndFailAll​(ChannelOutboundInvoker invoker, Throwable cause)
      Release all buffers in the queue and complete all listeners and promises.
      io.netty5.buffer.Buffer remove​(io.netty5.buffer.BufferAllocator alloc, int bytes, io.netty5.util.concurrent.Promise<Void> aggregatePromise)
      Remove a Buffer from the queue with the specified number of bytes.
      protected abstract io.netty5.buffer.Buffer removeEmptyValue()
      The value to return when remove(BufferAllocator, int, Promise) is called but the queue is empty.
      io.netty5.buffer.Buffer removeFirst​(io.netty5.util.concurrent.Promise<Void> aggregatePromise)
      Remove the first Buffer from the queue.
      protected int size()
      Get the number of elements in this queue added via one of the add(Buffer) methods.
      String toString()  
      void writeAndRemoveAll​(ChannelHandlerContext ctx)
      Writes all remaining elements in this queue.
    • Constructor Detail

      • AbstractCoalescingBufferQueue

        protected AbstractCoalescingBufferQueue​(int initSize)
        Create a new instance.
        Parameters:
        initSize - the initial size of the underlying queue.
    • Method Detail

      • addFirst

        public final void addFirst​(io.netty5.buffer.Buffer buf,
                                   io.netty5.util.concurrent.Promise<Void> promise)
        Add a buffer to the front of the queue and associate a promise with it that should be completed when all the buffer's bytes have been consumed from the queue and written.
        Parameters:
        buf - to add to the head of the queue
        promise - to complete when all the bytes have been consumed and written, can be void.
      • add

        public final void add​(io.netty5.buffer.Buffer buf)
        Add a buffer to the end of the queue.
      • add

        public final void add​(io.netty5.buffer.Buffer buf,
                              io.netty5.util.concurrent.Promise<Void> promise)
        Add a buffer to the end of the queue and associate a promise with it that should be completed when all the buffer's bytes have been consumed from the queue and written.
        Parameters:
        buf - to add to the tail of the queue
        promise - to complete when all the bytes have been consumed and written, can be void.
      • add

        public final void add​(io.netty5.buffer.Buffer buf,
                              io.netty5.util.concurrent.FutureListener<Void> listener)
        Add a buffer to the end of the queue and associate a listener with it that should be completed when all the buffers bytes have been consumed from the queue and written.
        Parameters:
        buf - to add to the tail of the queue
        listener - to notify when all the bytes have been consumed and written, can be null.
      • removeFirst

        public final io.netty5.buffer.Buffer removeFirst​(io.netty5.util.concurrent.Promise<Void> aggregatePromise)
        Remove the first Buffer from the queue.
        Parameters:
        aggregatePromise - used to aggregate the promises and listeners for the returned buffer.
        Returns:
        the first Buffer from the queue.
      • remove

        public final io.netty5.buffer.Buffer remove​(io.netty5.buffer.BufferAllocator alloc,
                                                    int bytes,
                                                    io.netty5.util.concurrent.Promise<Void> aggregatePromise)
        Remove a Buffer from the queue with the specified number of bytes. Any added buffer whose bytes are fully consumed during removal will have their promise completed when the passed aggregate Promise completes.
        Parameters:
        alloc - The allocator used if a new Buffer is generated during the aggregation process.
        bytes - the maximum number of readable bytes in the returned Buffer, if bytes is greater than readableBytes then a buffer of length readableBytes is returned.
        aggregatePromise - used to aggregate the promises and listeners for the constituent buffers.
        Returns:
        a Buffer composed of the enqueued buffers.
      • readableBytes

        public final int readableBytes()
        The number of readable bytes.
      • isEmpty

        public final boolean isEmpty()
        Are there pending buffers in the queue.
      • releaseAndFailAll

        public final void releaseAndFailAll​(ChannelOutboundInvoker invoker,
                                            Throwable cause)
        Release all buffers in the queue and complete all listeners and promises.
      • copyTo

        public final void copyTo​(AbstractCoalescingBufferQueue dest)
        Copy all pending entries in this queue into the destination queue.
        Parameters:
        dest - to copy pending buffers to.
      • writeAndRemoveAll

        public final void writeAndRemoveAll​(ChannelHandlerContext ctx)
        Writes all remaining elements in this queue.
        Parameters:
        ctx - The context to write all elements to.
      • compose

        protected abstract io.netty5.buffer.Buffer compose​(io.netty5.buffer.BufferAllocator alloc,
                                                           io.netty5.buffer.Buffer cumulation,
                                                           io.netty5.buffer.Buffer next)
        Calculate the result of current + next.
      • composeIntoComposite

        protected final io.netty5.buffer.Buffer composeIntoComposite​(io.netty5.buffer.BufferAllocator alloc,
                                                                     io.netty5.buffer.Buffer cumulation,
                                                                     io.netty5.buffer.Buffer next)
        Compose cumulation and next into a new CompositeBuffer.
      • copyAndCompose

        protected final io.netty5.buffer.Buffer copyAndCompose​(io.netty5.buffer.BufferAllocator alloc,
                                                               io.netty5.buffer.Buffer cumulation,
                                                               io.netty5.buffer.Buffer next,
                                                               int minIncrement)
        Compose cumulation and next into a new Buffer suitable for IO.
        Parameters:
        alloc - The allocator to use to allocate the new buffer.
        cumulation - The current cumulation.
        next - The next buffer.
        minIncrement - The minimum buffer size - the resulting buffer will grow by at least this much.
        Returns:
        The result of cumulation + next.
      • composeFirst

        protected io.netty5.buffer.Buffer composeFirst​(io.netty5.buffer.BufferAllocator allocator,
                                                       io.netty5.buffer.Buffer first)
        Calculate the first Buffer which will be used in subsequent calls to compose(BufferAllocator, Buffer, Buffer).
      • removeEmptyValue

        protected abstract io.netty5.buffer.Buffer removeEmptyValue()
        The value to return when remove(BufferAllocator, int, Promise) is called but the queue is empty.
        Returns:
        the Buffer which represents an empty queue.
      • size

        protected final int size()
        Get the number of elements in this queue added via one of the add(Buffer) methods.
        Returns:
        the number of elements in this queue.