- java.lang.Object
-
- io.netty5.channel.AbstractCoalescingBufferQueue
-
- Direct Known Subclasses:
CoalescingBufferQueue
@UnstableApi public abstract class AbstractCoalescingBufferQueue extends Object
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractCoalescingBufferQueue(int initSize)Create a new instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidadd(Buffer buf)Add a buffer to the end of the queue.voidadd(Buffer buf, FutureListener<Void> 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.voidadd(Buffer buf, Promise<Void> 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.voidaddFirst(Buffer buf, Promise<Void> 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 abstract Buffercompose(BufferAllocator alloc, Buffer cumulation, Buffer next)Calculate the result ofcurrent + next.protected BuffercomposeFirst(BufferAllocator allocator, Buffer first)Calculate the firstBufferwhich will be used in subsequent calls tocompose(BufferAllocator, Buffer, Buffer).protected BuffercomposeIntoComposite(BufferAllocator alloc, Buffer cumulation, Buffer next)protected BuffercopyAndCompose(BufferAllocator alloc, Buffer cumulation, Buffer next, int minIncrement)voidcopyTo(AbstractCoalescingBufferQueue dest)Copy all pending entries in this queue into the destination queue.booleanisEmpty()Are there pending buffers in the queue.intreadableBytes()The number of readable bytes.voidreleaseAndFailAll(ChannelOutboundInvoker invoker, Throwable cause)Release all buffers in the queue and complete all listeners and promises.Bufferremove(BufferAllocator alloc, int bytes, Promise<Void> aggregatePromise)Remove aBufferfrom the queue with the specified number of bytes.protected abstract BufferremoveEmptyValue()The value to return whenremove(BufferAllocator, int, Promise)is called but the queue is empty.BufferremoveFirst(Promise<Void> aggregatePromise)Remove the firstBufferfrom the queue.protected intsize()Get the number of elements in this queue added via one of theadd(Buffer)methods.StringtoString()voidwriteAndRemoveAll(ChannelHandlerContext ctx)Writes all remaining elements in this queue.
-
-
-
Method Detail
-
addFirst
public final void addFirst(Buffer buf, Promise<Void> 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 queuepromise- to complete when all the bytes have been consumed and written, can be void.
-
add
public final void add(Buffer buf)
Add a buffer to the end of the queue.
-
add
public final void add(Buffer buf, Promise<Void> 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 queuepromise- to complete when all the bytes have been consumed and written, can be void.
-
add
public final void add(Buffer buf, FutureListener<Void> 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 queuelistener- to notify when all the bytes have been consumed and written, can benull.
-
removeFirst
public final Buffer removeFirst(Promise<Void> aggregatePromise)
Remove the firstBufferfrom the queue.- Parameters:
aggregatePromise- used to aggregate the promises and listeners for the returned buffer.- Returns:
- the first
Bufferfrom the queue.
-
remove
public final Buffer remove(BufferAllocator alloc, int bytes, Promise<Void> aggregatePromise)
Remove aBufferfrom the queue with the specified number of bytes. Any added buffer whose bytes are fully consumed during removal will have their promise completed when the passed aggregatePromisecompletes.- Parameters:
alloc- The allocator used if a newBufferis generated during the aggregation process.bytes- the maximum number of readable bytes in the returnedBuffer, ifbytesis greater thanreadableBytesthen a buffer of lengthreadableBytesis returned.aggregatePromise- used to aggregate the promises and listeners for the constituent buffers.- Returns:
- a
Buffercomposed 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, 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.
-
compose
protected abstract Buffer compose(BufferAllocator alloc, Buffer cumulation, Buffer next)
Calculate the result ofcurrent + next.
-
composeIntoComposite
protected final Buffer composeIntoComposite(BufferAllocator alloc, Buffer cumulation, Buffer next)
-
copyAndCompose
protected final Buffer copyAndCompose(BufferAllocator alloc, Buffer cumulation, Buffer next, int minIncrement)
- Parameters:
alloc- The allocator to use to allocate the new buffer.cumulation- The current cumulation.next- The next buffer.minIncrement- The minimum buffer size - the resulting buffer will grow by at least this much.- Returns:
- The result of
cumulation + next.
-
composeFirst
protected Buffer composeFirst(BufferAllocator allocator, Buffer first)
Calculate the firstBufferwhich will be used in subsequent calls tocompose(BufferAllocator, Buffer, Buffer).
-
removeEmptyValue
protected abstract Buffer removeEmptyValue()
The value to return whenremove(BufferAllocator, int, Promise)is called but the queue is empty.- Returns:
- the
Bufferwhich represents an empty queue.
-
size
protected final int size()
Get the number of elements in this queue added via one of theadd(Buffer)methods.- Returns:
- the number of elements in this queue.
-
-