Package org.bluezoo.gumdrop
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:
TCPEndpoint- TCP stream endpoints
- Author:
- Chris Burdess
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumChannel handler types for efficient dispatch in the selector loop. -
Method Summary
Modifier and TypeMethodDescriptionReturns the type of this channel handler for dispatch purposes.Returns the SelectionKey associated with this handler.Returns the SelectorLoop this handler is registered with.default TimerHandlescheduleTimer(long delayMs, Runnable callback) Schedules a callback to be executed after the specified delay.voidSets the SelectionKey for this handler.voidsetSelectorLoop(SelectorLoop loop) Sets the SelectorLoop for this handler.
-
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
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
Sets the SelectorLoop for this handler. Called by SelectorLoop during registration.- Parameters:
loop- the selector loop
-
scheduleTimer
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 executedcallback- the callback to execute- Returns:
- a handle that can be used to cancel the timer
-