Class CommandContext
java.lang.Object
com.loomcache.server.network.CommandContext
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 Summary
ConstructorsConstructorDescriptionCommandContext(Message message, ConnectionContext connection) Create a new command context for pipelined execution. -
Method Summary
Modifier and TypeMethodDescriptionGet the connection context for response writing.longGet the time elapsed since enqueue (in milliseconds).longGet the time this command was enqueued (in nanoseconds).message()Get the message to execute.static voidremovePeerSequence(String peerId) Removes the sequence number counter for a disconnected peer to prevent memory leaks.toString()
-
Constructor Details
-
CommandContext
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
-
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
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
-