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 Type
    Method
    Description
    @Nullable Message
    Handle an incoming message and optionally return a response.
    default void
    Called when a peer disconnects.
    default void
    onPeerDisconnect(String peerId, long connectionCreatedAtNanos)
    Called when a specific peer connection is closed.
  • Method Details

    • handleMessage

      @Nullable Message handleMessage(Message message, ConnectionContext sender)
      Handle an incoming message and optionally return a response.
      Parameters:
      message - the incoming message
      sender - the connection context of the sender
      Returns:
      response message, or null if no response needed
    • onPeerDisconnect

      default void onPeerDisconnect(String peerId)
      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

      default void onPeerDisconnect(String peerId, long connectionCreatedAtNanos)
      Called when a specific peer connection is closed.
      Parameters:
      peerId - the ID of the peer that disconnected
      connectionCreatedAtNanos - the closed connection's creation timestamp