Class AbstractEventStore
- All Implemented Interfaces:
DomainEventSequenceAware,EventBus,EventStore,MessageDispatchInterceptorSupport<EventMessage<?>>,StreamableMessageSource<TrackedEventMessage<?>>,SubscribableMessageSource<EventMessage<?>>
- Direct Known Subclasses:
AxonServerEventStore,EmbeddedEventStore,EmbeddedEventStore
EventStore that uses a EventStorageEngine to store and load events.- Since:
- 3.0
- Author:
- Rene de Waele
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAbstract Builder class to instantiate anAbstractEventStore. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInstantiate anAbstractEventStorebased on the fields contained in theAbstractEventStore.Builder. -
Method Summary
Modifier and TypeMethodDescriptionCreates the token at the end of an event stream.Creates the token at the beginning of an event stream.createTokenAt(Instant dateTime) Creates a token that tracks all events after givendateTime.protected Optional<DomainEventMessage<?>> handleSnapshotReadingError(String aggregateIdentifier, Throwable e) Invoked when an error (ExceptionorLinkageError) occurs while attempting to read a snapshot event.lastSequenceNumberFor(String aggregateIdentifier) Returns the last known sequence number of an Event for the givenaggregateIdentifier.protected voidprepareCommit(List<? extends EventMessage<?>> events) Process giveneventswhile the Unit of Work root is preparing for commit.readEvents(String aggregateIdentifier) Open an event stream containing all domain events belonging to the givenaggregateIdentifier.readEvents(String aggregateIdentifier, long firstSequenceNumber) Open an event stream containing all domain events belonging to the givenaggregateIdentifier.protected Stream<? extends DomainEventMessage<?>> stagedDomainEventMessages(String aggregateIdentifier) Returns a Stream of all DomainEventMessages that have been staged for publication by an Aggregate with givenaggregateIdentifier.protected EventStorageEngineReturns theEventStorageEngineused by the event store.voidstoreSnapshot(DomainEventMessage<?> snapshot) Stores the given (temporary)snapshotevent.Methods inherited from class org.axonframework.eventhandling.AbstractEventBus
afterCommit, commit, intercept, publish, queuedMessages, registerDispatchInterceptor, subscribeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.messaging.MessageDispatchInterceptorSupport
registerDispatchInterceptorMethods inherited from interface org.axonframework.messaging.StreamableMessageSource
createTokenSince, openStreamMethods inherited from interface org.axonframework.messaging.SubscribableMessageSource
subscribe
-
Constructor Details
-
AbstractEventStore
Instantiate anAbstractEventStorebased on the fields contained in theAbstractEventStore.Builder.Will assert that the
EventStorageEngineis notnull, and will throw anAxonConfigurationExceptionif it isnull.- Parameters:
builder- theAbstractEventStore.Builderused to instantiate aAbstractEventStoreinstance
-
-
Method Details
-
prepareCommit
Description copied from class:AbstractEventBusProcess giveneventswhile the Unit of Work root is preparing for commit. The default implementation signals the registeredMessageMonitorthat the given events are ingested and passes the events to each registered event processor.- Overrides:
prepareCommitin classAbstractEventBus- Parameters:
events- Events to be published by this Event Bus
-
readEvents
Open an event stream containing all domain events belonging to the givenaggregateIdentifier.The returned stream is finite, ending with the last known event of the aggregate. If the event store holds no events of the given aggregate an empty stream is returned.
This implementation returns a
DomainEventStreamstarting with the last stored snapshot of the aggregate followed by subsequent domain events.- Specified by:
readEventsin interfaceEventStore- Parameters:
aggregateIdentifier- the identifier of the aggregate whose events to fetch- Returns:
- a stream of all currently stored events of the aggregate
-
handleSnapshotReadingError
protected Optional<DomainEventMessage<?>> handleSnapshotReadingError(String aggregateIdentifier, Throwable e) Invoked when an error (ExceptionorLinkageError) occurs while attempting to read a snapshot event. This method can be overridden to change the default behavior, which is to log the exception (warn level) and ignore the snapshot.Overriding implementations may choose to return normally, or raise an exception. Exceptions raised from this method are propagated to the caller of the
readEvents(String)orreadEvents(String, long)methods.Returning an empty Optional will force the initialization of the aggregate to happen based on the entire event stream of that aggregate.
- Parameters:
aggregateIdentifier- The identifier of the aggregate for which an snapshot failed to loade- The exception or error that occurred while loading or deserializing the snapshot- Returns:
- An optional DomainEventMessage to use as the snapshot for this aggregate
- Throws:
RuntimeException- any runtimeException to fail loading the
-
stagedDomainEventMessages
protected Stream<? extends DomainEventMessage<?>> stagedDomainEventMessages(String aggregateIdentifier) Returns a Stream of all DomainEventMessages that have been staged for publication by an Aggregate with givenaggregateIdentifier.- Parameters:
aggregateIdentifier- The identifier of the aggregate to get staged events for- Returns:
- a Stream of DomainEventMessage of the identified aggregate
-
readEvents
Description copied from interface:EventStoreOpen an event stream containing all domain events belonging to the givenaggregateIdentifier.The returned stream is finite, ending with the last known event of the aggregate. If the event store holds no events of the given aggregate an empty stream is returned.
The default implementation invokes
EventStore.readEvents(String)and then filters out events with a sequence number smaller thanfirstSequenceNumber.- Specified by:
readEventsin interfaceEventStore- Parameters:
aggregateIdentifier- the identifier of the aggregate whose events to fetchfirstSequenceNumber- the expected sequence number of the first event in the returned stream- Returns:
- a stream of all currently stored events of the aggregate
-
storeSnapshot
Description copied from interface:EventStoreStores the given (temporary)snapshotevent. This snapshot replaces the segment of the event stream identified by thesnapshot'sAggregate Identifierup to (and including) the event with thesnapshot'ssequence number.These snapshots will only affect the
DomainEventStreamreturned by theEventStore.readEvents(String)method. They do not change the events returned byStreamableMessageSource.openStream(TrackingToken)or those received by usingSubscribableMessageSource.subscribe(java.util.function.Consumer).Note that snapshots are considered a temporary replacement for Events, and are used as performance optimization. Event Store implementations may choose to ignore or delete snapshots.
- Specified by:
storeSnapshotin interfaceEventStore- Parameters:
snapshot- The snapshot to replace part of the DomainEventStream.
-
storageEngine
Returns theEventStorageEngineused by the event store.- Returns:
- The event storage engine used by this event store
-
lastSequenceNumberFor
Description copied from interface:DomainEventSequenceAwareReturns the last known sequence number of an Event for the givenaggregateIdentifier.It is preferred to retrieve the last known sequence number from the Domain Event Stream when sourcing an Aggregate from events. However, this method provides an alternative in cases no events have been read. For example when using state storage.
- Specified by:
lastSequenceNumberForin interfaceDomainEventSequenceAware- Specified by:
lastSequenceNumberForin interfaceEventStore- Parameters:
aggregateIdentifier- the identifier of the aggregate to find the highest sequence for- Returns:
- an optional containing the highest sequence number found, or an empty optional is no events are found for this aggregate
-
createTailToken
Description copied from interface:StreamableMessageSourceCreates the token at the beginning of an event stream. The beginning of an event stream in this context means the token of very first event in the stream.The default behavior for this method is to return
null, which always represents the tail position of a stream. However, implementations are encouraged to return an instance that explicitly represents the tail of the stream.- Specified by:
createTailTokenin interfaceStreamableMessageSource<TrackedEventMessage<?>>- Returns:
- the token at the beginning of an event stream
-
createHeadToken
Description copied from interface:StreamableMessageSourceCreates the token at the end of an event stream. The end of an event stream in this context means the token of very last event in the stream.- Specified by:
createHeadTokenin interfaceStreamableMessageSource<TrackedEventMessage<?>>- Returns:
- the token at the end of an event stream
-
createTokenAt
Description copied from interface:StreamableMessageSourceCreates 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 interfaceStreamableMessageSource<TrackedEventMessage<?>>- Parameters:
dateTime- The date and time for determining criteria how the tracking token should be created. A tracking token should point at 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
-