Package io.netty.channel
Class CoalescingBufferQueue
- java.lang.Object
-
- io.netty.channel.AbstractCoalescingBufferQueue
-
- io.netty.channel.CoalescingBufferQueue
-
public final class CoalescingBufferQueue extends AbstractCoalescingBufferQueue
A FIFO queue of bytes where producers add bytes by repeatedly addingByteBufand 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 Summary
Constructors Constructor Description CoalescingBufferQueue(Channel channel)CoalescingBufferQueue(Channel channel, int initSize)CoalescingBufferQueue(Channel channel, int initSize, boolean updateWritability)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ByteBufcompose(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf next)Calculate the result ofcurrent + next.voidreleaseAndFailAll(java.lang.Throwable cause)Release all buffers in the queue and complete all listeners and promises.ByteBufremove(int bytes, ChannelPromise aggregatePromise)Remove aByteBuffrom the queue with the specified number of bytes.protected ByteBufremoveEmptyValue()The value to return whenAbstractCoalescingBufferQueue.remove(ByteBufAllocator, int, ChannelPromise)is called but the queue is empty.-
Methods inherited from class io.netty.channel.AbstractCoalescingBufferQueue
add, add, add, addFirst, composeFirst, composeFirst, composeIntoComposite, copyAndCompose, copyTo, isEmpty, readableBytes, releaseAndFailAll, remove, removeFirst, size, toString, writeAndRemoveAll
-
-
-
-
Method Detail
-
remove
public ByteBuf remove(int bytes, ChannelPromise aggregatePromise)
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
public void releaseAndFailAll(java.lang.Throwable cause)
Release all buffers in the queue and complete all listeners and promises.
-
compose
protected ByteBuf compose(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf next)
Description copied from class:AbstractCoalescingBufferQueueCalculate the result ofcurrent + next.- Specified by:
composein classAbstractCoalescingBufferQueue
-
removeEmptyValue
protected ByteBuf 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.
-
-