CommandResultAccessor
interface 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
}
}Content copied to clipboard