Interface ChannelHandler

All Known Implementing Classes:
QuicEngine, TCPEndpoint, UDPEndpoint

public interface ChannelHandler
Common interface for objects attached to SelectionKeys in the SelectorLoop. This interface allows the SelectorLoop to dispatch I/O events efficiently using a type discriminator rather than instanceof checks.

Implementations include:

Author:
Chris Burdess
  • Method Details

    • getChannelType

      ChannelHandler.Type getChannelType()
      Returns the type of this channel handler for dispatch purposes.
      Returns:
      the channel handler type
    • getSelectionKey

      SelectionKey getSelectionKey()
      Returns the SelectionKey associated with this handler.
      Returns:
      the selection key, or null if not yet registered
    • setSelectionKey

      void setSelectionKey(SelectionKey key)
      Sets the SelectionKey for this handler. Called by SelectorLoop during registration.
      Parameters:
      key - the selection key
    • getSelectorLoop

      SelectorLoop getSelectorLoop()
      Returns the SelectorLoop this handler is registered with.
      Returns:
      the selector loop, or null if not yet registered
    • setSelectorLoop

      void setSelectorLoop(SelectorLoop loop)
      Sets the SelectorLoop for this handler. Called by SelectorLoop during registration.
      Parameters:
      loop - the selector loop
    • scheduleTimer

      default TimerHandle scheduleTimer(long delayMs, Runnable callback)
      Schedules a callback to be executed after the specified delay. The callback will be executed on this handler's SelectorLoop thread, making it safe to perform I/O operations.

      Common use cases include:

      • Periodic keep-alive or ping messages
      • Connection/request timeouts
      • Delayed retry operations
      Parameters:
      delayMs - delay in milliseconds before the callback is executed
      callback - the callback to execute
      Returns:
      a handle that can be used to cancel the timer