Class AbstractEventStorageEngine
- All Implemented Interfaces:
EventStorageEngine
- Direct Known Subclasses:
BatchingEventStorageEngine
EventStorageEngine implementation that takes care of event serialization and upcasting.- Since:
- 3.0
- Author:
- Rene de Waele
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAbstract Builder class to instantiate anAbstractEventStorageEngine. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInstantiate aAbstractEventStorageEnginebased on the fields contained in theAbstractEventStorageEngine.Builder. -
Method Summary
Modifier and TypeMethodDescriptionvoidappendEvents(List<? extends EventMessage<?>> events) Append a list of events to the event storage.protected abstract voidappendEvents(List<? extends EventMessage<?>> events, Serializer serializer) Append giveneventsto the backing database.Get the serializer used by this storage engine when storing and retrieving events.Get the serializer used by this storage engine when storing and retrieving snapshots.protected voidhandlePersistenceException(Exception exception, EventMessage<?> failedEvent) Invoke when an Exception is raised while persisting an Event or Snapshot.protected abstract Stream<? extends DomainEventData<?>> readEventData(String identifier, long firstSequenceNumber) Returns aStreamof serialized event data entries for an aggregate with givenidentifier.protected abstract Stream<? extends TrackedEventData<?>> readEventData(TrackingToken trackingToken, boolean mayBlock) Returns a globalStreamcontaining all serialized event data entries in the event storage that have aTrackingTokengreater than the giventrackingToken.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.protected abstract Stream<? extends DomainEventData<?>> readSnapshotData(String aggregateIdentifier) Returns a stream of serialized event entries for givenaggregateIdentifierif the backing database contains a snapshot of the aggregate.voidstoreSnapshot(DomainEventMessage<?> snapshot) Store an event that contains a snapshot of an aggregate.protected abstract voidstoreSnapshot(DomainEventMessage<?> snapshot, Serializer serializer) Store the givensnapshotof 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, createHeadToken, createTailToken, createTokenAt, lastSequenceNumberFor, readEvents
-
Field Details
-
upcasterChain
-
-
Constructor Details
-
AbstractEventStorageEngine
Instantiate aAbstractEventStorageEnginebased on the fields contained in theAbstractEventStorageEngine.Builder.Will assert that the event and snapshot
Serializerare notnull, and will throw anAxonConfigurationExceptionif any of them isnull.- Parameters:
builder- theAbstractEventStorageEngine.Builderused to instantiate aAbstractEventStorageEngineinstance
-
-
Method Details
-
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
-
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
-
handlePersistenceException
Invoke when an Exception is raised while persisting an Event or Snapshot.- Parameters:
exception- The exception raised while persisting an EventfailedEvent- The EventMessage that could not be persisted
-
appendEvents
Append giveneventsto the backing database. Use the givenserializerto serialize the event's payload and metadata.- Parameters:
events- Events to append to the databaseserializer- Serializer used to convert the events to a suitable format for storage
-
storeSnapshot
Store the givensnapshotof an Aggregate. Implementations may override any existing snapshot of the Aggregate with the given snapshot.- Parameters:
snapshot- Snapshot Event of the aggregateserializer- Serializer used to convert the snapshot event to a suitable format for storage
-
readEventData
protected abstract Stream<? extends DomainEventData<?>> readEventData(String identifier, long firstSequenceNumber) Returns aStreamof serialized event data entries for an aggregate with givenidentifier. The events should be ordered by aggregate sequence number and have a sequence number starting from the givenfirstSequenceNumber.- Parameters:
identifier- The identifier of the aggregate to open a stream forfirstSequenceNumber- The sequence number of the first excepted event entry- Returns:
- a Stream of serialized event entries for the given aggregate
-
readEventData
protected abstract Stream<? extends TrackedEventData<?>> readEventData(TrackingToken trackingToken, boolean mayBlock) Returns a globalStreamcontaining all serialized event data entries in the event storage that have aTrackingTokengreater than the giventrackingToken. Event entries in the stream should be ordered by tracking token. If thetrackingTokenisnulla stream containing all events should be returned.If the end of the stream is reached and
mayBlockistruethe stream may block to wait for new events.- 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
-
readSnapshotData
protected abstract Stream<? extends DomainEventData<?>> readSnapshotData(String aggregateIdentifier) Returns a stream of serialized event entries for givenaggregateIdentifierif the backing database contains a snapshot of the aggregate.It is required that specific event storage engines return snapshots in descending order of their sequence number.
- Parameters:
aggregateIdentifier- The aggregate identifier to fetch a snapshot for- Returns:
- A stream of serialized snapshots of the aggregate
-
getSnapshotSerializer
Get the serializer used by this storage engine when storing and retrieving snapshots.- Returns:
- the serializer used by this storage
-
getEventSerializer
Get the serializer used by this storage engine when storing and retrieving events.- Returns:
- the serializer used by this storage
-