@UnstableApi public abstract class AbstractCoalescingBufferQueue extends Object
Modifier | Constructor and Description |
---|---|
protected |
AbstractCoalescingBufferQueue(Channel channel,
int initSize)
Create a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
add(ByteBuf buf)
Add a buffer to the end of the queue.
|
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.
|
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.
|
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 of
current + next . |
protected ByteBuf |
composeFirst(ByteBufAllocator allocator,
ByteBuf first)
Deprecated.
Use {AbstractCoalescingBufferQueue#composeFirst(ByteBufAllocator, ByteBuf, int)}
|
protected ByteBuf |
composeFirst(ByteBufAllocator allocator,
ByteBuf first,
int bufferSize)
Calculate the first
ByteBuf which will be used in subsequent calls to
compose(ByteBufAllocator, ByteBuf, ByteBuf) . |
protected ByteBuf |
composeIntoComposite(ByteBufAllocator alloc,
ByteBuf cumulation,
ByteBuf next)
|
protected ByteBuf |
copyAndCompose(ByteBufAllocator alloc,
ByteBuf cumulation,
ByteBuf next)
|
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.
|
ByteBuf |
remove(ByteBufAllocator alloc,
int bytes,
ChannelPromise aggregatePromise)
Remove a
ByteBuf from the queue with the specified number of bytes. |
protected abstract ByteBuf |
removeEmptyValue()
The value to return when
remove(ByteBufAllocator, int, ChannelPromise) is called but the queue is empty. |
ByteBuf |
removeFirst(ChannelPromise aggregatePromise)
Remove the first
ByteBuf from the queue. |
protected int |
size()
Get the number of elements in this queue added via one of the
add(ByteBuf) methods. |
String |
toString() |
void |
writeAndRemoveAll(ChannelHandlerContext ctx)
Writes all remaining elements in this queue.
|
protected AbstractCoalescingBufferQueue(Channel channel, int initSize)
channel
- the Channel
which will have the Channel.isWritable()
reflect the amount of queued
buffers or null
if there is no writability state updated.initSize
- the initial size of the underlying queue.public final void addFirst(ByteBuf buf, ChannelPromise promise)
buf
- to add to the head of the queuepromise
- to complete when all the bytes have been consumed and written, can be void.public final void add(ByteBuf buf)
public final void add(ByteBuf buf, ChannelPromise promise)
buf
- to add to the tail of the queuepromise
- to complete when all the bytes have been consumed and written, can be void.public final void add(ByteBuf buf, ChannelFutureListener listener)
buf
- to add to the tail of the queuelistener
- to notify when all the bytes have been consumed and written, can be null
.public final ByteBuf removeFirst(ChannelPromise aggregatePromise)
ByteBuf
from the queue.aggregatePromise
- used to aggregate the promises and listeners for the returned buffer.ByteBuf
from the queue.public final ByteBuf remove(ByteBufAllocator alloc, int bytes, ChannelPromise aggregatePromise)
ByteBuf
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 aggregate ChannelPromise
completes.alloc
- The allocator used if a new ByteBuf
is generated during the aggregation process.bytes
- the maximum number of readable bytes in the returned ByteBuf
, if bytes
is greater
than readableBytes
then a buffer of length readableBytes
is returned.aggregatePromise
- used to aggregate the promises and listeners for the constituent buffers.ByteBuf
composed of the enqueued buffers.public final int readableBytes()
public final boolean isEmpty()
public final void releaseAndFailAll(ChannelOutboundInvoker invoker, Throwable cause)
public final void copyTo(AbstractCoalescingBufferQueue dest)
dest
- to copy pending buffers to.public final void writeAndRemoveAll(ChannelHandlerContext ctx)
ctx
- The context to write all elements to.protected abstract ByteBuf compose(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf next)
current + next
.protected final ByteBuf composeIntoComposite(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf next)
protected final ByteBuf copyAndCompose(ByteBufAllocator alloc, ByteBuf cumulation, ByteBuf next)
alloc
- The allocator to use to allocate the new buffer.cumulation
- The current cumulation.next
- The next buffer.cumulation + next
.protected ByteBuf composeFirst(ByteBufAllocator allocator, ByteBuf first, int bufferSize)
ByteBuf
which will be used in subsequent calls to
compose(ByteBufAllocator, ByteBuf, ByteBuf)
.bufferSize
- the optimal size of the buffer needed for cumulation@Deprecated protected ByteBuf composeFirst(ByteBufAllocator allocator, ByteBuf first)
ByteBuf
which will be used in subsequent calls to
compose(ByteBufAllocator, ByteBuf, ByteBuf)
.
This method is deprecated and will be removed in the future. Implementing classes should
override composeFirst(ByteBufAllocator, ByteBuf, int)
instead.protected abstract ByteBuf removeEmptyValue()
remove(ByteBufAllocator, int, ChannelPromise)
is called but the queue is empty.ByteBuf
which represents an empty queue.protected final int size()
add(ByteBuf)
methods.Copyright © 2008–2024 The Netty Project. All rights reserved.