Package io.netty.channel
Class AbstractCoalescingBufferQueue
java.lang.Object
io.netty.channel.AbstractCoalescingBufferQueue
- Direct Known Subclasses:
CoalescingBufferQueue
,SslHandler.SslHandlerCoalescingBufferQueue
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ArrayDeque
<Object> private static final InternalLogger
private int
private final PendingBytesTracker
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractCoalescingBufferQueue
(Channel channel, int initSize) Create a new instance. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
Add a buffer to the end of the queue.final void
add
(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 void
add
(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.private void
addFirst
(ByteBuf buf, ChannelFutureListener listener) final void
addFirst
(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 abstract ByteBuf
compose
(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf next) Calculate the result ofcurrent + next
.protected ByteBuf
composeFirst
(ByteBufAllocator allocator, ByteBuf first) Calculate the firstByteBuf
which will be used in subsequent calls tocompose(ByteBufAllocator, ByteBuf, ByteBuf)
.protected final ByteBuf
composeIntoComposite
(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf next) protected final ByteBuf
copyAndCompose
(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf next) final void
Copy all pending entries in this queue into the destination queue.private void
decrementReadableBytes
(int decrement) private void
incrementReadableBytes
(int increment) final boolean
isEmpty()
Are there pending buffers in the queue.final int
The number of readable bytes.private void
releaseAndCompleteAll
(ChannelFuture future) final void
releaseAndFailAll
(ChannelOutboundInvoker invoker, Throwable cause) Release all buffers in the queue and complete all listeners and promises.final ByteBuf
remove
(ByteBufAllocator alloc, int bytes, ChannelPromise aggregatePromise) Remove aByteBuf
from the queue with the specified number of bytes.protected abstract ByteBuf
The value to return whenremove(ByteBufAllocator, int, ChannelPromise)
is called but the queue is empty.final ByteBuf
removeFirst
(ChannelPromise aggregatePromise) Remove the firstByteBuf
from the queue.protected final int
size()
Get the number of elements in this queue added via one of theadd(ByteBuf)
methods.private static ChannelFutureListener
toChannelFutureListener
(ChannelPromise promise) toString()
final void
Writes all remaining elements in this queue.
-
Field Details
-
logger
-
bufAndListenerPairs
-
tracker
-
readableBytes
private int readableBytes
-
-
Constructor Details
-
AbstractCoalescingBufferQueue
Create a new instance.- Parameters:
channel
- theChannel
which will have theChannel.isWritable()
reflect the amount of queued buffers ornull
if there is no writability state updated.initSize
- the initial size of the underlying queue.
-
-
Method Details
-
addFirst
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.
-
addFirst
-
add
Add a buffer to the end of the queue. -
add
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
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
Remove the firstByteBuf
from the queue.- Parameters:
aggregatePromise
- used to aggregate the promises and listeners for the returned buffer.- Returns:
- the first
ByteBuf
from the queue.
-
remove
Remove aByteBuf
from 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 aggregateChannelPromise
completes.- Parameters:
alloc
- The allocator used if a newByteBuf
is generated during the aggregation process.bytes
- the maximum number of readable bytes in the returnedByteBuf
, 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
ByteBuf
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
Release all buffers in the queue and complete all listeners and promises. -
copyTo
Copy all pending entries in this queue into the destination queue.- Parameters:
dest
- to copy pending buffers to.
-
writeAndRemoveAll
Writes all remaining elements in this queue.- Parameters:
ctx
- The context to write all elements to.
-
toString
-
compose
Calculate the result ofcurrent + next
. -
composeIntoComposite
protected final ByteBuf composeIntoComposite(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf next) -
copyAndCompose
- Parameters:
alloc
- The allocator to use to allocate the new buffer.cumulation
- The current cumulation.next
- The next buffer.- Returns:
- The result of
cumulation + next
.
-
composeFirst
Calculate the firstByteBuf
which will be used in subsequent calls tocompose(ByteBufAllocator, ByteBuf, ByteBuf)
. -
removeEmptyValue
The value to return whenremove(ByteBufAllocator, int, ChannelPromise)
is called but the queue is empty.- Returns:
- the
ByteBuf
which represents an empty queue.
-
size
protected final int size()Get the number of elements in this queue added via one of theadd(ByteBuf)
methods.- Returns:
- the number of elements in this queue.
-
releaseAndCompleteAll
-
incrementReadableBytes
private void incrementReadableBytes(int increment) -
decrementReadableBytes
private void decrementReadableBytes(int decrement) -
toChannelFutureListener
-