Class CoalescingBufferQueue
java.lang.Object
io.netty.channel.AbstractCoalescingBufferQueue
io.netty.channel.CoalescingBufferQueue
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, ChannelPromise) completes.
This functionality is useful for aggregating or partitioning writes into fixed size buffers for framing protocols such as HTTP2.
-
Constructor Summary
ConstructorsConstructorDescriptionCoalescingBufferQueue(Channel channel) CoalescingBufferQueue(Channel channel, int initSize) CoalescingBufferQueue(Channel channel, int initSize, boolean updateWritability) -
Method Summary
Modifier and TypeMethodDescriptionprotected ByteBufcompose(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf next) Calculate the result ofcurrent + next.voidreleaseAndFailAll(Throwable cause) Release all buffers in the queue and complete all listeners and promises.remove(int bytes, ChannelPromise aggregatePromise) Remove aByteBuffrom the queue with the specified number of bytes.protected ByteBufThe value to return whenAbstractCoalescingBufferQueue.remove(ByteBufAllocator, int, ChannelPromise)is called but the queue is empty.Methods inherited from class AbstractCoalescingBufferQueue
add, add, add, addFirst, composeFirst, composeFirst, composeIntoComposite, copyAndCompose, copyTo, isEmpty, readableBytes, releaseAndFailAll, remove, removeFirst, size, toString, writeAndRemoveAllModifier and TypeMethodDescriptionfinal voidAdd a buffer to the end of the queue.final voidadd(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.final voidadd(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.final voidaddFirst(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.protected ByteBufcomposeFirst(ByteBufAllocator allocator, ByteBuf first) Deprecated.Use {AbstractCoalescingBufferQueue#composeFirst(ByteBufAllocator, ByteBuf, int)}protected ByteBufcomposeFirst(ByteBufAllocator allocator, ByteBuf first, int bufferSize) Calculate the firstByteBufwhich will be used in subsequent calls toAbstractCoalescingBufferQueue.compose(ByteBufAllocator, ByteBuf, ByteBuf).protected final ByteBufcomposeIntoComposite(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf next) protected final ByteBufcopyAndCompose(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf next) final voidCopy all pending entries in this queue into the destination queue.final booleanisEmpty()Are there pending buffers in the queue.final intThe number of readable bytes.final voidreleaseAndFailAll(ChannelOutboundInvoker invoker, Throwable cause) Release all buffers in the queue and complete all listeners and promises.final ByteBufremove(ByteBufAllocator alloc, int bytes, ChannelPromise aggregatePromise) Remove aByteBuffrom the queue with the specified number of bytes.final ByteBufremoveFirst(ChannelPromise aggregatePromise) Remove the firstByteBuffrom the queue.protected final intsize()Get the number of elements in this queue added via one of theAbstractCoalescingBufferQueue.add(ByteBuf)methods.toString()final voidWrites all remaining elements in this queue.
-
Constructor Details
-
CoalescingBufferQueue
-
CoalescingBufferQueue
-
CoalescingBufferQueue
-
-
Method Details
-
remove
Remove aByteBuffrom 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 aggregateChannelPromisecompletes.- Parameters:
bytes- the maximum number of readable bytes in the returnedByteBuf, ifbytesis greater thanAbstractCoalescingBufferQueue.readableBytesthen a buffer of lengthAbstractCoalescingBufferQueue.readableBytesis returned.aggregatePromise- used to aggregate the promises and listeners for the constituent buffers.- Returns:
- a
ByteBufcomposed of the enqueued buffers.
-
releaseAndFailAll
Release all buffers in the queue and complete all listeners and promises. -
compose
Description copied from class:AbstractCoalescingBufferQueueCalculate the result ofcurrent + next.- Specified by:
composein classAbstractCoalescingBufferQueue
-
removeEmptyValue
Description copied from class:AbstractCoalescingBufferQueueThe value to return whenAbstractCoalescingBufferQueue.remove(ByteBufAllocator, int, ChannelPromise)is called but the queue is empty.- Specified by:
removeEmptyValuein classAbstractCoalescingBufferQueue- Returns:
- the
ByteBufwhich represents an empty queue.
-