public class SequenceEventStorageEngine extends Object implements EventStorageEngine
New events and snapshots are stored in the active storage.
When fetching snapshots, if a snapshot cannot be found in the active storage it will be obtained from the historic storage.
No mechanism is provided to move events from the active storage to the historic storage engine so clients need to take care of this themselves.
Constructor and Description |
---|
SequenceEventStorageEngine(EventStorageEngine historicStorage,
EventStorageEngine activeStorage)
|
Modifier and Type | Method and Description |
---|---|
void |
appendEvents(List<? extends EventMessage<?>> events)
Append a list of events to the event storage.
|
DomainEventStream |
readEvents(String aggregateIdentifier,
long firstSequenceNumber)
Get a
DomainEventStream containing all events published by the aggregate with given aggregateIdentifier starting with the first event having a sequence number that is equal or larger than the
given firstSequenceNumber . |
Stream<? extends TrackedEventMessage<?>> |
readEvents(TrackingToken trackingToken,
boolean mayBlock)
Open an event stream containing all events stored since given tracking token.
|
Optional<DomainEventMessage<?>> |
readSnapshot(String aggregateIdentifier)
Try to load a snapshot event of the aggregate with given
aggregateIdentifier . |
void |
storeSnapshot(DomainEventMessage<?> snapshot)
Store an event that contains a snapshot of an aggregate.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
appendEvents, readEvents
public SequenceEventStorageEngine(EventStorageEngine historicStorage, EventStorageEngine activeStorage)
historicStorage
- the event storage engine that contains historic events. This can be backed by a read-only
databaseactiveStorage
- the event storage engine that contains 'new' events and to which new events and snapshots
will be writtenpublic void appendEvents(List<? extends EventMessage<?>> events)
EventStorageEngine
Note that all events should have a unique event identifier. When storing domain events
events should also have a unique combination of aggregate id and sequence number.
appendEvents
in interface EventStorageEngine
events
- Events to append to the event storagepublic void storeSnapshot(DomainEventMessage<?> snapshot)
EventStorageEngine
storeSnapshot
in interface EventStorageEngine
snapshot
- The snapshot event of the aggregate that is to be storedpublic Stream<? extends TrackedEventMessage<?>> readEvents(TrackingToken trackingToken, boolean mayBlock)
EventStorageEngine
trackingToken
of null
to open
a stream containing all available events.
If the value of the given mayBlock
is true
the returned stream is allowed to block while waiting
for new event messages if the end of the stream is reached.
readEvents
in interface EventStorageEngine
trackingToken
- Object describing the global index of the last processed event or null
to create a
stream of all events in the storemayBlock
- If true
the storage engine may optionally choose to block to wait for new event
messages if the end of the stream is reached.public DomainEventStream readEvents(String aggregateIdentifier, long firstSequenceNumber)
EventStorageEngine
DomainEventStream
containing all events published by the aggregate with given aggregateIdentifier
starting with the first event having a sequence number that is equal or larger than the
given firstSequenceNumber
.
The returned stream is finite, i.e. it should not block to wait for further events if the end of the event stream of the aggregate is reached.
readEvents
in interface EventStorageEngine
aggregateIdentifier
- The identifier of the aggregatefirstSequenceNumber
- The expected sequence number of the first event in the returned streampublic Optional<DomainEventMessage<?>> readSnapshot(String aggregateIdentifier)
EventStorageEngine
aggregateIdentifier
. If the storage engine has
no snapshot event of the aggregate, an empty Optional is returned.readSnapshot
in interface EventStorageEngine
aggregateIdentifier
- The identifier of the aggregateCopyright © 2010–2017. All rights reserved.