public abstract class AbstractEventStore extends org.axonframework.eventhandling.AbstractEventBus implements EventStore
EventStore that uses a EventStorageEngine to store and load events.| Modifier and Type | Class and Description |
|---|---|
static class |
AbstractEventStore.Builder
Abstract Builder class to instantiate an
AbstractEventStore. |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractEventStore(AbstractEventStore.Builder builder)
Instantiate an
AbstractEventStore based on the fields contained in the AbstractEventStore.Builder. |
| Modifier and Type | Method and Description |
|---|---|
org.axonframework.eventhandling.TrackingToken |
createHeadToken() |
org.axonframework.eventhandling.TrackingToken |
createTailToken() |
org.axonframework.eventhandling.TrackingToken |
createTokenAt(Instant dateTime) |
protected Optional<org.axonframework.eventhandling.DomainEventMessage<?>> |
handleSnapshotReadingError(String aggregateIdentifier,
Throwable e)
Invoked when an error (
Exception or LinkageError) occurs while attempting to read a snapshot
event. |
Optional<Long> |
lastSequenceNumberFor(String aggregateIdentifier) |
protected void |
prepareCommit(List<? extends org.axonframework.eventhandling.EventMessage<?>> events) |
DomainEventStream |
readEvents(String aggregateIdentifier)
Open an event stream containing all domain events belonging to the given
aggregateIdentifier. |
DomainEventStream |
readEvents(String aggregateIdentifier,
long firstSequenceNumber)
Open an event stream containing all domain events belonging to the given
aggregateIdentifier. |
protected Stream<? extends org.axonframework.eventhandling.DomainEventMessage<?>> |
stagedDomainEventMessages(String aggregateIdentifier)
Returns a Stream of all DomainEventMessages that have been staged for publication by an Aggregate with given
aggregateIdentifier. |
protected EventStorageEngine |
storageEngine()
Returns the
EventStorageEngine used by the event store. |
void |
storeSnapshot(org.axonframework.eventhandling.DomainEventMessage<?> snapshot)
Stores the given (temporary)
snapshot event. |
afterCommit, commit, intercept, publish, queuedMessages, registerDispatchInterceptor, subscribeclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitprotected AbstractEventStore(AbstractEventStore.Builder builder)
AbstractEventStore based on the fields contained in the AbstractEventStore.Builder.
Will assert that the EventStorageEngine is not null, and will throw an
AxonConfigurationException if it is null.
builder - the AbstractEventStore.Builder used to instantiate a AbstractEventStore instanceprotected void prepareCommit(List<? extends org.axonframework.eventhandling.EventMessage<?>> events)
prepareCommit in class org.axonframework.eventhandling.AbstractEventBuspublic DomainEventStream readEvents(@Nonnull String aggregateIdentifier)
aggregateIdentifier.
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 DomainEventStream starting with the last stored snapshot of the aggregate
followed by subsequent domain events.
readEvents in interface EventStoreaggregateIdentifier - the identifier of the aggregate whose events to fetchprotected Optional<org.axonframework.eventhandling.DomainEventMessage<?>> handleSnapshotReadingError(String aggregateIdentifier, Throwable e)
Exception or LinkageError) 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) or readEvents(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.
aggregateIdentifier - The identifier of the aggregate for which an snapshot failed to loade - The exception or error that occurred while loading or deserializing the snapshotRuntimeException - any runtimeException to fail loading theprotected Stream<? extends org.axonframework.eventhandling.DomainEventMessage<?>> stagedDomainEventMessages(String aggregateIdentifier)
aggregateIdentifier.aggregateIdentifier - The identifier of the aggregate to get staged events forpublic DomainEventStream readEvents(@Nonnull String aggregateIdentifier, long firstSequenceNumber)
EventStoreaggregateIdentifier.
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 than firstSequenceNumber.
readEvents in interface EventStoreaggregateIdentifier - the identifier of the aggregate whose events to fetchfirstSequenceNumber - the expected sequence number of the first event in the returned streampublic void storeSnapshot(@Nonnull org.axonframework.eventhandling.DomainEventMessage<?> snapshot)
EventStoresnapshot event. This snapshot replaces the segment of the event stream
identified by the snapshot's Aggregate Identifier up
to (and including) the event with the snapshot's sequence
number.
These snapshots will only affect the DomainEventStream returned by the EventStore.readEvents(String)
method. They do not change the events returned by StreamableMessageSource.openStream(TrackingToken) or those received
by using SubscribableMessageSource.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.
storeSnapshot in interface EventStoresnapshot - The snapshot to replace part of the DomainEventStream.protected EventStorageEngine storageEngine()
EventStorageEngine used by the event store.public Optional<Long> lastSequenceNumberFor(String aggregateIdentifier)
lastSequenceNumberFor in interface org.axonframework.eventhandling.DomainEventSequenceAwarelastSequenceNumberFor in interface EventStorepublic org.axonframework.eventhandling.TrackingToken createTailToken()
createTailToken in interface org.axonframework.messaging.StreamableMessageSource<org.axonframework.eventhandling.TrackedEventMessage<?>>public org.axonframework.eventhandling.TrackingToken createHeadToken()
createHeadToken in interface org.axonframework.messaging.StreamableMessageSource<org.axonframework.eventhandling.TrackedEventMessage<?>>public org.axonframework.eventhandling.TrackingToken createTokenAt(Instant dateTime)
createTokenAt in interface org.axonframework.messaging.StreamableMessageSource<org.axonframework.eventhandling.TrackedEventMessage<?>>Copyright © 2010–2024. All rights reserved.