Interface SourcingStrategy
- All Known Implementing Classes:
SourcingStrategy.Absolute,SourcingStrategy.Snapshot
public sealed interface SourcingStrategy
permits SourcingStrategy.Absolute, SourcingStrategy.Snapshot
Defines how a sourcing operation should construct the message stream when reading events
from an event store.
There are two supported forms:
SourcingStrategy.Absolute- start from a concrete position in the event streamSourcingStrategy.Snapshot- include a snapshot (if available), followed by subsequent events
Merging
Sourcing strategies can be merged to produce a single effective strategy used for sourcing. The merge rules are deterministic:- Merging two
SourcingStrategy.Absolutestrategies results in the minimum of both positions - Merging an
Absolutewith aSnapshotalways results in theSnapshot - Merging two
Snapshotinstances is not supported and results in an exception
Snapshot semantics
TheSourcingStrategy.Snapshot strategy provides initial state, replacing the initial part of the event stream if
initial state was available. It
is identified by:
- A
QualifiedName, defining the snapshot type - An identifier (typically an aggregate or entity id)
- An optional maximum
Position, limiting which snapshots are acceptable
- The latest snapshot matching the identity whose position is at or before the specified maximum position
- All subsequent events from the snapshot’s position onward
- Since:
- 5.1.1
- Author:
- John Hendrikx
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordAbsolute start position in the event stream.static final recordSnapshot-based sourcing strategy. -
Method Summary
Modifier and TypeMethodDescriptionmerge(SourcingStrategy other) Merges this sourcing strategy with another sourcing strategy to produce a single effective strategy for event sourcing.
-
Method Details
-
merge
Merges this sourcing strategy with another sourcing strategy to produce a single effective strategy for event sourcing.The merge operation is deterministic and defined as follows:
- Merging two
SourcingStrategy.Absolutestrategies results in anAbsolutewhose position is the minimum of both positions - Merging an
SourcingStrategy.Absolutewith aSourcingStrategy.Snapshotresults in theSnapshot - Merging two
SourcingStrategy.Snapshotinstances is not supported and results in anUnsupportedOperationException
- Parameters:
other- the other sourcing strategy to merge with this one, cannot benull- Returns:
- the merged sourcing strategy
- Throws:
UnsupportedOperationException- if both strategies areSourcingStrategy.SnapshotinstancesNullPointerException- if any argument isnull
- Merging two
-