Class CoalescingBufferQueue


  • public final class CoalescingBufferQueue
    extends AbstractCoalescingBufferQueue
    A FIFO queue of bytes where producers add bytes by repeatedly adding ByteBuf and consumers take bytes in arbitrary lengths. This allows producers to add lots of small buffers and the consumer to take all the bytes out in a single buffer. Conversely the producer may add larger buffers and the consumer could take the bytes in many small buffers.

    Bytes are added and removed with promises. If the last byte of a buffer added with a promise is removed then that promise will complete when the promise passed to remove(int, io.netty.channel.ChannelPromise) completes.

    This functionality is useful for aggregating or partitioning writes into fixed size buffers for framing protocols such as HTTP2.

    • Constructor Detail

      • CoalescingBufferQueue

        public CoalescingBufferQueue​(Channel channel)
      • CoalescingBufferQueue

        public CoalescingBufferQueue​(Channel channel,
                                     int initSize)
      • CoalescingBufferQueue

        public CoalescingBufferQueue​(Channel channel,
                                     int initSize,
                                     boolean updateWritability)
    • Method Detail

      • remove

        public io.netty.buffer.ByteBuf remove​(int bytes,
                                              ChannelPromise aggregatePromise)
        Remove a ByteBuf from the queue with the specified number of bytes. Any added buffer who's bytes are fully consumed during removal will have it's promise completed when the passed aggregate ChannelPromise completes.
        Parameters:
        bytes - the maximum number of readable bytes in the returned ByteBuf, if bytes is greater than AbstractCoalescingBufferQueue.readableBytes then a buffer of length AbstractCoalescingBufferQueue.readableBytes is returned.
        aggregatePromise - used to aggregate the promises and listeners for the constituent buffers.
        Returns:
        a ByteBuf composed of the enqueued buffers.
      • releaseAndFailAll

        public void releaseAndFailAll​(Throwable cause)
        Release all buffers in the queue and complete all listeners and promises.
      • compose

        protected io.netty.buffer.ByteBuf compose​(io.netty.buffer.ByteBufAllocator alloc,
                                                  io.netty.buffer.ByteBuf cumulation,
                                                  io.netty.buffer.ByteBuf next)
        Description copied from class: AbstractCoalescingBufferQueue
        Calculate the result of current + next.
        Specified by:
        compose in class AbstractCoalescingBufferQueue