Class DataOperationHandler

java.lang.Object
com.loomcache.server.handler.DataOperationHandler

public class DataOperationHandler extends Object
Handles all data-structure operations received over the binary protocol.

Translates incoming MAP_GET, MAP_PUT, QUEUE_OFFER, TOPIC_PUBLISH, SET_ADD, etc. messages into calls on the local DataStructureRegistry, and returns the appropriate response messages.

This handler forms the server-side counterpart to the client SDK's methods (mapGet, mapPut, queueOffer, etc.), completing the request-response path for all cache data-structure operations over the wire protocol.

Operation Categories

  • Map Operations: get, put, delete, contains, size, putIfAbsent, replace, clear
  • Queue Operations: offer, poll, peek, size
  • Topic Operations: publish
  • Set Operations: add, remove, contains, size, clear
  • Lock Operations: tryLock, unlock, isLocked, forceUnlock
  • Counter Operations: get, set, increment, decrement, add, compareAndSet

Thread Safety

This handler is stateless and thread-safe. It may be called concurrently from multiple virtual threads (one per connection), all accessing the shared DataStructureRegistry through thread-safe data structures.
Since:
1.0
  • Constructor Details

    • DataOperationHandler

      public DataOperationHandler(DataStructureRegistry registry, int instanceNumber)
      Creates a new DataOperationHandler.
      Parameters:
      registry - the registry containing all distributed data structures on this node (non-null)
      instanceNumber - the instance number of this cache node (used for logging, non-negative)
      Throws:
      NullPointerException - if registry is null
  • Method Details

    • setNearCacheInvalidationManager

      public void setNearCacheInvalidationManager(@Nullable NearCacheInvalidationManager manager)
      Set the near cache invalidation manager for server-push invalidation. Called after construction since TcpServer must be started first.
      Parameters:
      manager - the invalidation manager (may be null to disable)
    • setEventListenerManager

      public void setEventListenerManager(@Nullable DistributedEventListenerManager manager)
      Set the distributed event listener manager for entry event broadcasts. Called after construction since TcpServer must be started first.
      Parameters:
      manager - the event listener manager (may be null to disable)
    • setLoomMetrics

      public void setLoomMetrics(@Nullable LoomMetrics metrics)
      Set the LoomMetrics instance for latency tracking. Called after metrics initialization to enable command latency instrumentation.
      Parameters:
      metrics - the LoomMetrics instance (may be null to disable latency tracking)
    • setTransactionKeyLockManager

      public void setTransactionKeyLockManager(@Nullable TransactionKeyLockManager lockManager)
    • setMutationLock

      public void setMutationLock(@Nullable ReentrantLock lock)
      Set the shared mutation lock for serializing writes with atomic batch operations. When set, all write operations acquire this lock to prevent interleaving with BatchExecutionHandler's snapshot/rollback windows.
      Parameters:
      lock - the shared mutation lock from BatchExecutionHandler (may be null to disable)
    • setLeaderCheck

      public void setLeaderCheck(@Nullable BooleanSupplier supplier)
      Set the leader check supplier for topic publish deduplication.

      When TOPIC_PUBLISH goes through Raft, every replica's state machine apply calls handleTopicPublish. Without this check, subscribers on ALL replicas receive the message (duplicate delivery). With this supplier, followers only store the message in the ringbuffer without notifying subscribers.

      Parameters:
      supplier - returns true if this node is the Raft leader (may be null to always notify)
    • handle

      public @Nullable Message handle(Message msg)
      Handles a single data-structure operation message.

      Dispatches the message based on its type (MAP_GET, QUEUE_OFFER, etc.) to the appropriate handler method, which executes the operation on the DataStructureRegistry and returns a response.

      Latency is tracked in nanoseconds: - apply_ns: time from handle() entry to response return (actual state machine operation)

      Parameters:
      msg - the incoming operation message (must not be null)
      Returns:
      a response message with the operation result, or null if the operation completes without requiring a response (rare)
    • isDataOperation

      public boolean isDataOperation(MessageType type)
      Returns true if this message type is a data operation we handle.
    • defaultTtlMillis

      public long defaultTtlMillis(String mapName)