Package io.netty.channel
Interface IoHandlerContext
-
public interface IoHandlerContext
The context for anIoHandler
that is run by anThreadAwareExecutor
. All methods MUST be executed on theThreadAwareExecutor
thread (which meansThreadAwareExecutor.isExecutorThread(Thread)
(Thread)} must returntrue
).
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description boolean
canBlock()
Returnstrue
if blocking for IO is allowed or if we should try to do a non-blocking request for IO to be ready.long
deadlineNanos()
Returns the absolute point in time at which the next closest scheduled task should run or-1
if nothing is scheduled to run.long
delayNanos(long currentTimeNanos)
Returns the amount of time left until the scheduled task with the closest deadline should run.default void
reportActiveIoTime(long activeNanos)
Reports the amount of time in nanoseconds that was spent actively processing I/O events.default boolean
shouldReportActiveIoTime()
Returnstrue
if the I/O handler should measure and report its active I/O time.
-
-
-
Method Detail
-
canBlock
boolean canBlock()
Returnstrue
if blocking for IO is allowed or if we should try to do a non-blocking request for IO to be ready.- Returns:
true
if allowed,false
otherwise.
-
delayNanos
long delayNanos(long currentTimeNanos)
Returns the amount of time left until the scheduled task with the closest deadline should run.- Parameters:
currentTimeNanos
- the current nanos.- Returns:
- nanos
-
deadlineNanos
long deadlineNanos()
Returns the absolute point in time at which the next closest scheduled task should run or-1
if nothing is scheduled to run.- Returns:
- deadline.
-
reportActiveIoTime
default void reportActiveIoTime(long activeNanos)
Reports the amount of time in nanoseconds that was spent actively processing I/O events.This metric is needed for the dynamic, utilization-based auto-scaling feature in
MultithreadEventExecutorGroup
. The reported time allows the auto-scaler to accurately measure the I/O workload of an event loop.IoHandler
implementations should measure the time spent in their event processing logic and report the duration via this method. This should only include time spent actively handling ready I/O events and should not include time spent blocking or waiting for I/O (e.g., in anepoll_wait
) call.The default implementation of this method is a no-op. Failing to override it in an
IoHandlerContext
that supports auto-scaling will result in the I/O utilization being perceived as zero.- Parameters:
activeNanos
- The duration in nanoseconds of active, non-blocking I/O work.
-
shouldReportActiveIoTime
default boolean shouldReportActiveIoTime()
Returnstrue
if the I/O handler should measure and report its active I/O time. This is used as a guard to avoid the overhead of callingSystem.nanoTime()
when the feature is not in use.- Returns:
true
if active I/O time should be reported,false
otherwise.
-
-