Package io.simplesource.api
Interface InvalidSequenceHandler<K,C,A>
-
- Type Parameters:
K- the aggregate key typeC- the command typeA- 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 areadSequence, 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. TheshouldRejectmethod 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 appropriateInvalidSequenceStrategywhen using theAggregateBuilderDSL.
-
-
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 keyexpectedSeq- the current sequence number of the aggregate (i.e. the lastest)currentSeq- the sequence number passed in the command requestcurrentAggregate- the current aggregate valuecommand- the command currently being invoked- Returns:
- If the command should be rejected, return
Optionalwith a reason. If the command should still be invoked, returnOptional.empty
-
-