Interface InvalidSequenceHandler<K,​C,​A>

  • Type Parameters:
    K - the aggregate key type
    C - the command type
    A - the aggregate type
    Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @FunctionalInterface
    public interface InvalidSequenceHandler<K,​C,​A>
    This functional for accepting or rejecting commands executed against an out of date view. An incoming command has a readSequence, which represents the clients view of the aggregate version. This sequence is checked against the sequence of the internally maintained aggregate version, which is guaranteed to be the latest. The shouldReject method will be invoked if and only if these versions do not agree Normally a client should not have to explicitly implement this interface. There are standard implementations that cover most use cases These are provided by choosing the appropriate InvalidSequenceStrategy when using the AggregateBuilder DSL.
    • Method Summary

      Modifier and Type Method Description
      Optional<CommandError> shouldReject​(K key, io.simplesource.data.Sequence expectedSeq, io.simplesource.data.Sequence currentSeq, A currentAggregate, C command)
      The sequence handler is responsible for accepting or rejecting commands executed against an out of date view If expectedSeq == currentSeq this handler will not be invoked If this handler is invoked, it means the is executing a command against an old version of the aggregate
    • Method Detail

      • shouldReject

        Optional<CommandError> shouldReject​(K key,
                                            io.simplesource.data.Sequence expectedSeq,
                                            io.simplesource.data.Sequence currentSeq,
                                            A currentAggregate,
                                            C command)
        The sequence handler is responsible for accepting or rejecting commands executed against an out of date view If expectedSeq == currentSeq this handler will not be invoked If this handler is invoked, it means the is executing a command against an old version of the aggregate
        Parameters:
        key - the aggregate key
        expectedSeq - the current sequence number of the aggregate (i.e. the lastest)
        currentSeq - the sequence number passed in the command request
        currentAggregate - the current aggregate value
        command - the command currently being invoked
        Returns:
        If the command should be rejected, return Optional with a reason. If the command should still be invoked, return Optional.empty