Interface MessageHandler
- All Known Implementing Classes:
CacheNode
public interface MessageHandler
Interface for handling incoming cache protocol messages and peer disconnections.
Implementations process the message and optionally return a response. Return null if no response is needed (e.g., for one-way messages like heartbeats).
The handler runs on the connection's virtual thread, so blocking is fine. However, keep processing fast to avoid head-of-line blocking for that connection.
-
Method Summary
Modifier and TypeMethodDescription@Nullable MessagehandleMessage(Message message, ConnectionContext sender) Handle an incoming message and optionally return a response.default voidonPeerDisconnect(String peerId) Called when a peer disconnects.default voidonPeerDisconnect(String peerId, long connectionCreatedAtNanos) Called when a specific peer connection is closed.
-
Method Details
-
handleMessage
Handle an incoming message and optionally return a response.- Parameters:
message- the incoming messagesender- the connection context of the sender- Returns:
- response message, or null if no response needed
-
onPeerDisconnect
Called when a peer disconnects. Implementations can use this to clean up resources, update cluster state, etc.- Parameters:
peerId- the ID of the peer that disconnected
-
onPeerDisconnect
Called when a specific peer connection is closed.- Parameters:
peerId- the ID of the peer that disconnectedconnectionCreatedAtNanos- the closed connection's creation timestamp
-