- java.lang.Object
-
- io.netty5.channel.AbstractCoalescingBufferQueue
-
- Direct Known Subclasses:
CoalescingBufferQueue
@UnstableApi public abstract class AbstractCoalescingBufferQueue extends Object
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractCoalescingBufferQueue(int initSize)
Create a new instance.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
add(Buffer buf)
Add a buffer to the end of the queue.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.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.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.protected abstract Buffer
compose(BufferAllocator alloc, Buffer cumulation, Buffer next)
Calculate the result ofcurrent + next
.protected Buffer
composeFirst(BufferAllocator allocator, Buffer first)
Calculate the firstBuffer
which will be used in subsequent calls tocompose(BufferAllocator, Buffer, Buffer)
.protected Buffer
composeIntoComposite(BufferAllocator alloc, Buffer cumulation, Buffer next)
protected Buffer
copyAndCompose(BufferAllocator alloc, Buffer cumulation, Buffer next, int minIncrement)
void
copyTo(AbstractCoalescingBufferQueue dest)
Copy all pending entries in this queue into the destination queue.boolean
isEmpty()
Are there pending buffers in the queue.int
readableBytes()
The number of readable bytes.void
releaseAndFailAll(ChannelOutboundInvoker invoker, Throwable cause)
Release all buffers in the queue and complete all listeners and promises.Buffer
remove(BufferAllocator alloc, int bytes, Promise<Void> aggregatePromise)
Remove aBuffer
from the queue with the specified number of bytes.protected abstract Buffer
removeEmptyValue()
The value to return whenremove(BufferAllocator, int, Promise)
is called but the queue is empty.Buffer
removeFirst(Promise<Void> aggregatePromise)
Remove the firstBuffer
from the queue.protected int
size()
Get the number of elements in this queue added via one of theadd(Buffer)
methods.String
toString()
void
writeAndRemoveAll(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 firstBuffer
from the queue.- Parameters:
aggregatePromise
- used to aggregate the promises and listeners for the returned buffer.- Returns:
- the first
Buffer
from the queue.
-
remove
public final Buffer remove(BufferAllocator alloc, 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 their promise completed when the passed aggregatePromise
completes.- Parameters:
alloc
- The allocator used if a newBuffer
is generated during the aggregation process.bytes
- the maximum number of readable bytes in the returnedBuffer
, ifbytes
is greater thanreadableBytes
then a buffer of lengthreadableBytes
is returned.aggregatePromise
- used to aggregate the promises and listeners for the constituent buffers.- Returns:
- a
Buffer
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, 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 firstBuffer
which 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
Buffer
which 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.
-
-