CommandResultAccessor

Provides access to command execution results for tracking and idempotency purposes.

This interface allows storing and retrieving the outcomes of command processing, which is essential for:

  • Implementing idempotent command handling

  • Caching command results

  • Auditing command executions

  • Supporting distributed command processing

Results are stored as key-value pairs where keys are unique identifiers and values can be any serializable object.

See also

for the command structure

Example usage:

class CommandProcessor(private val resultAccessor: CommandResultAccessor) {
fun processCommand(command: CommandMessage<*>): Any? {
val result = resultAccessor.getCommandResult<Any>(command.commandId)
if (result != null) {
return result // Idempotent: return cached result
}
val newResult = executeCommand(command)
resultAccessor.setCommandResult(command.commandId, newResult)
return newResult
}
}

Functions

Link copied to clipboard
abstract fun getCommandResult(): Map<String, Any>

Retrieves all stored command results as a read-only map.

abstract fun <R> getCommandResult(key: String): R?

Retrieves a previously stored command result by its key.

Link copied to clipboard
abstract fun setCommandResult(key: String, value: Any)

Stores the result of a command execution for later retrieval.