Interface IoHandler

All Known Implementing Classes:
EpollIoHandler, IoUringIoHandler, KQueueIoHandler, LocalIoHandler, NioIoHandler

public interface IoHandler
Handles IO dispatching for an ThreadAwareExecutor. All operations except wakeup() and isCompatible(Class) MUST be executed on the ThreadAwareExecutor thread (which means ThreadAwareExecutor.isExecutorThread(Thread) must return true) and should never be called from the user-directly.

Once a IoHandle is registered via the register(IoHandle) method it's possible to submit IoOps related to the IoHandle via IoRegistration.submit(IoOps). These submitted IoOps are the "source" of IoEvents that are dispatched to the registered IoHandle via the IoHandle.handle(IoRegistration, IoEvent) method. These events must be consumed (and handled) as otherwise they might be reported again until handled.

  • Method Details

    • initialize

      default void initialize()
      Initialize this IoHandler.
    • run

      int run(IoHandlerContext context)
      Run the IO handled by this IoHandler. The IoHandlerContext should be used to ensure we not execute too long and so block the processing of other task that are scheduled on the ThreadAwareExecutor. This is done by taking IoHandlerContext.delayNanos(long) or IoHandlerContext.deadlineNanos() into account.
      Parameters:
      context - the IoHandlerContext.
      Returns:
      the number of IoHandle for which I/O was handled. Internal events such as wakeups and timer expirations must not be included in this count.
    • prepareToDestroy

      default void prepareToDestroy()
      Prepare to destroy this IoHandler. This method will be called before destroy() and may be called multiple times.
    • destroy

      default void destroy()
      Destroy the IoHandler and free all its resources. Once destroyed using the IoHandler will cause undefined behaviour.
    • register

      IoRegistration register(IoHandle handle) throws Exception
      Register a IoHandle for IO.
      Parameters:
      handle - the IoHandle to register.
      Throws:
      Exception - thrown if an error happens during registration.
    • wakeup

      void wakeup()
      Wakeup the IoHandler, which means if any operation blocks it should be unblocked and return as soon as possible.
    • isCompatible

      boolean isCompatible(Class<? extends IoHandle> handleType)
      Returns true if the given type is compatible with this IoHandler and so can be registered, false otherwise.
      Parameters:
      handleType - the type of the IoHandle.
      Returns:
      if compatible of not.