Class CommandContext

java.lang.Object
com.loomcache.server.network.CommandContext

public final class CommandContext extends Object
Wraps a message and its associated connection context for pipelined command execution.

This allows decoupling I/O parsing from command execution: - Reader thread: parse → create CommandContext → enqueue - Executor threads: dequeue → execute → write response

Thread-safe for passing between threads (immutable after construction).

Includes a per-peer sequence number to ensure FIFO ordering can be verified and enforced in the executor pool, even with multiple executor threads.

Since:
1.0
  • Constructor Details

    • CommandContext

      public CommandContext(Message message, ConnectionContext connection)
      Create a new command context for pipelined execution.
      Parameters:
      message - the parsed message to execute (non-null)
      connection - the connection context for response writing (non-null)
      Throws:
      NullPointerException - if message or connection is null
  • Method Details

    • message

      public Message message()
      Get the message to execute.
      Returns:
      the non-null message
    • connection

      public ConnectionContext connection()
      Get the connection context for response writing.
      Returns:
      the non-null connection context
    • enqueuedAtNanos

      public long enqueuedAtNanos()
      Get the time this command was enqueued (in nanoseconds).
      Returns:
      the enqueue timestamp in nanoseconds
    • elapsedMs

      public long elapsedMs()
      Get the time elapsed since enqueue (in milliseconds).
      Returns:
      the elapsed time in milliseconds
    • removePeerSequence

      public static void removePeerSequence(String peerId)
      Removes the sequence number counter for a disconnected peer to prevent memory leaks. Must be called when a peer disconnects to clean up the static tracking map.
      Parameters:
      peerId - the peer identifier to remove
    • toString

      public String toString()
      Overrides:
      toString in class Object