Class IovArrayReferenceCollector
java.lang.Object
io.netty.channel.uring.IovArrayReferenceCollector
- All Implemented Interfaces:
ChannelOutboundBuffer.MessageProcessor
final class IovArrayReferenceCollector
extends Object
implements ChannelOutboundBuffer.MessageProcessor
Fills the
IoUringIoHandler's IovArray from flushed outbound messages and records the
ByteBuf behind each entry it added, so the caller can copy those references into a WriteOperation
slot once the SQE is built.
One instance per IoUringIoHandler, matching the IovArray it wraps: the handler hands out the
same IovArray instance to every channel it services, so a per-channel collector would be scoped smaller
than the array it fills. This collector is only ever valid between a reset() and the WriteOperation
record call that copies its references out -- the caller then resets it from a finally that also covers
the submit, so every exit from the write path, including the ones that throw, leaves it empty. Without that reset
this instance, being permanently owned by the event loop rather than any one channel, would keep the previous
write's buffers reachable for as long as this event loop went without servicing another write.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidprivate voidgrow()Doubles the backing array once it fills up.booleanprocessMessage(Object msg) Will be called for each flushed message until it either there are no more flushed messages or this method returnsfalse.private voidrecordIfAdded(Object msg, int previousCount) Records the buffer behindmsgonceIovArrayactually gained an entry for it.(package private) ReferenceCounted[](package private) int(package private) voidreset()Drops the previous references, keeping the array for reuse.
-
Field Details
-
iovArray
-
references
-
count
private int count
-
-
Constructor Details
-
IovArrayReferenceCollector
IovArrayReferenceCollector(IovArray iovArray)
-
-
Method Details
-
reset
void reset()Drops the previous references, keeping the array for reuse. Nulls out the dropped entries too: otherwise a smaller write reusing the collector after a larger one would leave staleByteBufreferences reachable through the backing array until the next reset, which risks promoting them into an old generation. -
processMessage
Description copied from interface:ChannelOutboundBuffer.MessageProcessorWill be called for each flushed message until it either there are no more flushed messages or this method returnsfalse.- Specified by:
processMessagein interfaceChannelOutboundBuffer.MessageProcessor- Throws:
Exception
-
recordIfAdded
Records the buffer behindmsgonceIovArrayactually gained an entry for it. Split out ofprocessMessage(Object)so that method stays under HotSpot's default inline size threshold (35 bytes), which it exceeded with theifcheck below inlined. -
referencesArray
ReferenceCounted[] referencesArray() -
referencesCount
int referencesCount() -
add
-
grow
private void grow()Doubles the backing array once it fills up. Split out ofadd(ByteBuf)so that method stays under HotSpot's default inline size threshold (35 bytes); growing is genuinely the rare branch here, sincereset()clears the array in place for reuse instead of shrinking it back down.
-