Interface IoHandlerContext
public interface IoHandlerContext
The context for an
IoHandler that is run by an ThreadAwareExecutor.
All methods MUST be executed on the ThreadAwareExecutor thread
(which means ThreadAwareExecutor.isExecutorThread(Thread) (Thread)} must return true).-
Method Summary
Modifier and TypeMethodDescriptionbooleancanBlock()Returnstrueif blocking for IO is allowed or if we should try to do a non-blocking request for IO to be ready.longReturns the absolute point in time at which the next closest scheduled task should run or-1if nothing is scheduled to run.longdelayNanos(long currentTimeNanos) Returns the amount of time left until the scheduled task with the closest deadline should run.default voidreportActiveIoTime(long activeNanos) Reports the amount of time in nanoseconds that was spent actively processing I/O events.default booleanReturnstrueif the I/O handler should measure and report its active I/O time.
-
Method Details
-
canBlock
boolean canBlock()Returnstrueif blocking for IO is allowed or if we should try to do a non-blocking request for IO to be ready.- Returns:
trueif allowed,falseotherwise.
-
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-1if 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.IoHandlerimplementations 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
IoHandlerContextthat 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()Returnstrueif 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:
trueif active I/O time should be reported,falseotherwise.
-