- java.lang.Object
-
- io.netty5.channel.AbstractCoalescingBufferQueue
-
- io.netty5.channel.CoalescingBufferQueue
-
public final class CoalescingBufferQueue extends AbstractCoalescingBufferQueue
A FIFO queue of bytes where producers add bytes by repeatedly addingBuffer
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.netty5.util.concurrent.Promise<java.lang.Void>)
completes.This functionality is useful for aggregating or partitioning writes into fixed size buffers for framing protocols such as HTTP2.
-
-
Constructor Summary
Constructors Constructor Description CoalescingBufferQueue(Channel channel)
CoalescingBufferQueue(Channel channel, int initSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Buffer
compose(BufferAllocator alloc, Buffer cumulation, Buffer next)
Calculate the result ofcurrent + next
.void
releaseAndFailAll(Throwable cause)
Release all buffers in the queue and complete all listeners and promises.Buffer
remove(int bytes, Promise<Void> aggregatePromise)
Remove aBuffer
from the queue with the specified number of bytes.protected Buffer
removeEmptyValue()
The value to return whenAbstractCoalescingBufferQueue.remove(BufferAllocator, int, Promise)
is called but the queue is empty.-
Methods inherited from class io.netty5.channel.AbstractCoalescingBufferQueue
add, add, add, addFirst, composeFirst, composeIntoComposite, copyAndCompose, copyTo, isEmpty, readableBytes, releaseAndFailAll, remove, removeFirst, size, toString, writeAndRemoveAll
-
-
-
-
Method Detail
-
remove
public Buffer remove(int bytes, Promise<Void> aggregatePromise)
Remove aBuffer
from the queue with the specified number of bytes. Any added buffer whose bytes are fully consumed during removal will have it's promise completed when the passed aggregatePromise
completes.- Parameters:
bytes
- the maximum number of readable bytes in the returnedBuffer
, ifbytes
is greater thanAbstractCoalescingBufferQueue.readableBytes()
then a buffer of lengthAbstractCoalescingBufferQueue.readableBytes()
is returned.aggregatePromise
- used to aggregate the promises and listeners for the constituent buffers.- Returns:
- a
Buffer
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 Buffer compose(BufferAllocator alloc, Buffer cumulation, Buffer next)
Description copied from class:AbstractCoalescingBufferQueue
Calculate the result ofcurrent + next
.- Specified by:
compose
in classAbstractCoalescingBufferQueue
-
removeEmptyValue
protected Buffer removeEmptyValue()
Description copied from class:AbstractCoalescingBufferQueue
The value to return whenAbstractCoalescingBufferQueue.remove(BufferAllocator, int, Promise)
is called but the queue is empty.- Specified by:
removeEmptyValue
in classAbstractCoalescingBufferQueue
- Returns:
- the
Buffer
which represents an empty queue.
-
-