Class SequenceEventStorageEngine
- All Implemented Interfaces:
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.
- Since:
- 3.0
- Author:
- Rene de Waele, Allard Buijze
-
Constructor Summary
ConstructorsConstructorDescriptionSequenceEventStorageEngine(EventStorageEngine historicStorage, EventStorageEngine activeStorage) -
Method Summary
Modifier and TypeMethodDescriptionvoidappendEvents(List<? extends EventMessage<?>> events) Append a list of events to the event storage.Creates a token that is at the head of an event stream - that tracks all new events.Creates a token that is at the tail of an event stream - that tracks events from the beginning of time.createTokenAt(Instant dateTime) Creates a token that tracks all events after givendateTime.lastSequenceNumberFor(String aggregateIdentifier) Returns the last known sequence number for the givenaggregateIdentifier.readEvents(String aggregateIdentifier, long firstSequenceNumber) Get aDomainEventStreamcontaining all events published by the aggregate with givenaggregateIdentifierstarting with the first event having a sequence number that is equal or larger than the givenfirstSequenceNumber.Stream<? extends TrackedEventMessage<?>> readEvents(TrackingToken trackingToken, boolean mayBlock) Open an event stream containing all events stored since given tracking token.readSnapshot(String aggregateIdentifier) Try to load a snapshot event of the aggregate with givenaggregateIdentifier.voidstoreSnapshot(DomainEventMessage<?> snapshot) Store an event that contains a snapshot of an aggregate.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.eventsourcing.eventstore.EventStorageEngine
appendEvents, readEvents
-
Constructor Details
-
SequenceEventStorageEngine
public SequenceEventStorageEngine(EventStorageEngine historicStorage, EventStorageEngine activeStorage) - Parameters:
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 written
-
-
Method Details
-
appendEvents
Description copied from interface:EventStorageEngineAppend a list of events to the event storage. Events will be appended in the order that they are offered in.Note that all events should have a unique event identifier. When storing
domain eventsevents should also have a unique combination of aggregate id and sequence number.- Specified by:
appendEventsin interfaceEventStorageEngine- Parameters:
events- Events to append to the event storage
-
storeSnapshot
Description copied from interface:EventStorageEngineStore an event that contains a snapshot of an aggregate. If the event storage already contains a snapshot for the same aggregate, then it will be replaced with the given snapshot.- Specified by:
storeSnapshotin interfaceEventStorageEngine- Parameters:
snapshot- The snapshot event of the aggregate that is to be stored
-
readEvents
public Stream<? extends TrackedEventMessage<?>> readEvents(TrackingToken trackingToken, boolean mayBlock) Description copied from interface:EventStorageEngineOpen an event stream containing all events stored since given tracking token. The returned stream is comprised of events from aggregates as well as other application events. Pass atrackingTokenofnullto open a stream containing all available events.If the value of the given
mayBlockistruethe returned stream is allowed to block while waiting for new event messages if the end of the stream is reached.- Specified by:
readEventsin interfaceEventStorageEngine- Parameters:
trackingToken- Object describing the global index of the last processed event ornullto create a stream of all events in the storemayBlock- Iftruethe storage engine may optionally choose to block to wait for new event messages if the end of the stream is reached.- Returns:
- A stream containing all tracked event messages stored since the given tracking token
-
readEvents
Description copied from interface:EventStorageEngineGet aDomainEventStreamcontaining all events published by the aggregate with givenaggregateIdentifierstarting with the first event having a sequence number that is equal or larger than the givenfirstSequenceNumber.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.
- Specified by:
readEventsin interfaceEventStorageEngine- Parameters:
aggregateIdentifier- The identifier of the aggregatefirstSequenceNumber- The expected sequence number of the first event in the returned stream- Returns:
- A non-blocking DomainEventStream of the given aggregate
-
readSnapshot
Description copied from interface:EventStorageEngineTry to load a snapshot event of the aggregate with givenaggregateIdentifier. If the storage engine has no snapshot event of the aggregate, an empty Optional is returned.- Specified by:
readSnapshotin interfaceEventStorageEngine- Parameters:
aggregateIdentifier- The identifier of the aggregate- Returns:
- An optional with a snapshot of the aggregate
-
lastSequenceNumberFor
Description copied from interface:EventStorageEngineReturns the last known sequence number for the givenaggregateIdentifier.While it's recommended to use the sequence numbers from the
DomainEventStream, there are cases where knowing the sequence number is required, without having read the actual events. In such case, this method is a viable alternative.- Specified by:
lastSequenceNumberForin interfaceEventStorageEngine- Parameters:
aggregateIdentifier- The identifier to find the last sequence number for- Returns:
- an optional with the highest sequence number, or an empty optional if the aggregate identifier wasn't found
-
createTailToken
Description copied from interface:EventStorageEngineCreates a token that is at the tail of an event stream - that tracks events from the beginning of time.- Specified by:
createTailTokenin interfaceEventStorageEngine- Returns:
- a tracking token at the tail of an event stream, if event stream is empty
nullis returned
-
createHeadToken
Description copied from interface:EventStorageEngineCreates a token that is at the head of an event stream - that tracks all new events.- Specified by:
createHeadTokenin interfaceEventStorageEngine- Returns:
- a tracking token at the head of an event stream, if event stream is empty
nullis returned
-
createTokenAt
Description copied from interface:EventStorageEngineCreates a token that tracks all events after givendateTime. If there is an event exactly at the givendateTime, it will be tracked too.- Specified by:
createTokenAtin interfaceEventStorageEngine- Parameters:
dateTime- The date and time for determining criteria how the tracking token should be created. A tracking token should point to very first event before this date and time.- Returns:
- a tracking token at the given
dateTime, if there aren't events matching this criterianullis returned
-