Class AbstractCoalescingBufferQueue

    • Constructor Detail

      • AbstractCoalescingBufferQueue

        protected AbstractCoalescingBufferQueue​(Channel channel,
                                                int initSize)
        Create a new instance.
        Parameters:
        channel - the Channel which will have the Channel.isWritable() reflect the amount of queued buffers or null if there is no writability state updated.
        initSize - the initial size of the underlying queue.
    • Method Detail

      • addFirst

        public final void addFirst​(ByteBuf buf,
                                   ChannelPromise 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​(ByteBuf buf)
        Add a buffer to the end of the queue.
      • add

        public final void add​(ByteBuf buf,
                              ChannelPromise 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​(ByteBuf buf,
                              ChannelFutureListener 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 ByteBuf removeFirst​(ChannelPromise aggregatePromise)
        Remove the first ByteBuf from the queue.
        Parameters:
        aggregatePromise - used to aggregate the promises and listeners for the returned buffer.
        Returns:
        the first ByteBuf from the queue.
      • remove

        public final ByteBuf remove​(ByteBufAllocator alloc,
                                    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:
        alloc - The allocator used if a new ByteBuf is generated during the aggregation process.
        bytes - the maximum number of readable bytes in the returned ByteBuf, 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 ByteBuf 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,
                                            java.lang.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.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • copyAndCompose

        protected final ByteBuf copyAndCompose​(ByteBufAllocator alloc,
                                               ByteBuf cumulation,
                                               ByteBuf next)
        Compose cumulation and next into a new ByteBufAllocator.ioBuffer().
        Parameters:
        alloc - The allocator to use to allocate the new buffer.
        cumulation - The current cumulation.
        next - The next buffer.
        Returns:
        The result of cumulation + next.
      • size

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