Interface CommandAPI<K,​C>

  • Type Parameters:
    K - the aggregate key type
    C - all commands for this aggregate

    public interface CommandAPI<K,​C>
    The public API for submitting commands against a given aggregate and querying where they have been successfully applied. For a command to be successfully applied, this sequence must be the same as the sequence id of the last applied event.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static class  CommandAPI.Request<K,​C>  
    • Method Summary

      Modifier and Type Method Description
      default io.simplesource.data.FutureResult<CommandError,​io.simplesource.data.Sequence> publishAndQueryCommand​(CommandAPI.Request<K,​C> commandRequest, java.time.Duration timeout)
      Chain together publishing a command then query the result.
      io.simplesource.data.FutureResult<CommandError,​CommandId> publishCommand​(CommandAPI.Request<K,​C> request)
      Submit the given command ready for processing.
      io.simplesource.data.FutureResult<CommandError,​io.simplesource.data.Sequence> queryCommandResult​(CommandId commandId, java.time.Duration timeout)
      Get the result of the execution of the command identified by the provided UUID.
    • Method Detail

      • publishCommand

        io.simplesource.data.FutureResult<CommandError,​CommandId> publishCommand​(CommandAPI.Request<K,​C> request)
        Submit the given command ready for processing. A successful result implies the command has been successfully queued ready to be processed by the command handler. The validation of the command and translation into events is done asynchronously after publishing and is not reflected in the result of this method.
        Parameters:
        request - command request.
        Returns:
        a FutureResult with the commandId echoed back if the command was successfully queued, otherwise a list of reasons for the failure.
      • queryCommandResult

        io.simplesource.data.FutureResult<CommandError,​io.simplesource.data.Sequence> queryCommandResult​(CommandId commandId,
                                                                                                               java.time.Duration timeout)
        Get the result of the execution of the command identified by the provided UUID. If the command was successful, return the highest sequence number of the generated events. If the command fails, return the failure reasons. Implementations of this method are permitted to have limited retention when querying commands. If a command is queried outside the retention window it will keep trying for the given timeout duration then fail with a Timeout error code.
        Parameters:
        commandId - the CommandId of the command to lookup the result for.
        timeout - how long to wait attempting to fetch the result before timing out.
        Returns:
        sequence number of aggregate.
      • publishAndQueryCommand

        default io.simplesource.data.FutureResult<CommandError,​io.simplesource.data.Sequence> publishAndQueryCommand​(CommandAPI.Request<K,​C> commandRequest,
                                                                                                                           java.time.Duration timeout)
        Chain together publishing a command then query the result.
        Parameters:
        commandRequest - the command request.
        timeout - how long to wait for processing to complete and the result to be available.
        Returns:
        sequence number of aggregate.