public abstract class AbstractEventStorageEngine extends Object implements EventStorageEngine
EventStorageEngine
implementation that takes care of event serialization and upcasting.Modifier and Type | Class and Description |
---|---|
static class |
AbstractEventStorageEngine.Builder
Abstract Builder class to instantiate an
AbstractEventStorageEngine . |
Modifier and Type | Field and Description |
---|---|
protected EventUpcaster |
upcasterChain |
Modifier | Constructor and Description |
---|---|
protected |
AbstractEventStorageEngine(AbstractEventStorageEngine.Builder builder)
Instantiate a
AbstractEventStorageEngine based on the fields contained in the AbstractEventStorageEngine.Builder . |
Modifier and Type | Method and Description |
---|---|
void |
appendEvents(List<? extends EventMessage<?>> events)
Append a list of events to the event storage.
|
protected abstract void |
appendEvents(List<? extends EventMessage<?>> events,
Serializer serializer)
Append given
events to the backing database. |
Serializer |
getEventSerializer()
Get the serializer used by this storage engine when storing and retrieving events.
|
Serializer |
getSnapshotSerializer()
Get the serializer used by this storage engine when storing and retrieving snapshots.
|
protected void |
handlePersistenceException(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 a
Stream of serialized event data entries for an aggregate with given identifier . |
protected abstract Stream<? extends TrackedEventData<?>> |
readEventData(TrackingToken trackingToken,
boolean mayBlock)
Returns a global
Stream containing all serialized event data entries in the event storage that have a
TrackingToken greater than the given trackingToken . |
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 . |
protected abstract Stream<? extends DomainEventData<?>> |
readSnapshotData(String aggregateIdentifier)
Returns a stream of serialized event entries for given
aggregateIdentifier if the backing database
contains a snapshot of the aggregate. |
void |
storeSnapshot(DomainEventMessage<?> snapshot)
Store an event that contains a snapshot of an aggregate.
|
protected abstract void |
storeSnapshot(DomainEventMessage<?> snapshot,
Serializer serializer)
Store the given
snapshot of an Aggregate. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
appendEvents, createHeadToken, createTailToken, createTokenAt, lastSequenceNumberFor, readEvents
protected final EventUpcaster upcasterChain
protected AbstractEventStorageEngine(AbstractEventStorageEngine.Builder builder)
AbstractEventStorageEngine
based on the fields contained in the AbstractEventStorageEngine.Builder
.
Will assert that the event and snapshot Serializer
are not null
, and will throw an AxonConfigurationException
if any of them is null
.
builder
- the AbstractEventStorageEngine.Builder
used to instantiate a AbstractEventStorageEngine
instancepublic 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 aggregatepublic 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 storedprotected void handlePersistenceException(Exception exception, EventMessage<?> failedEvent)
exception
- The exception raised while persisting an EventfailedEvent
- The EventMessage that could not be persistedprotected abstract void appendEvents(List<? extends EventMessage<?>> events, Serializer serializer)
events
to the backing database. Use the given serializer
to serialize the event's
payload and metadata.events
- Events to append to the databaseserializer
- Serializer used to convert the events to a suitable format for storageprotected abstract void storeSnapshot(DomainEventMessage<?> snapshot, Serializer serializer)
snapshot
of an Aggregate. Implementations may override any existing snapshot of the
Aggregate with the given snapshot.snapshot
- Snapshot Event of the aggregateserializer
- Serializer used to convert the snapshot event to a suitable format for storageprotected abstract Stream<? extends DomainEventData<?>> readEventData(String identifier, long firstSequenceNumber)
Stream
of serialized event data entries for an aggregate with given identifier
. The
events should be ordered by aggregate sequence number and have a sequence number starting from the given firstSequenceNumber
.identifier
- The identifier of the aggregate to open a stream forfirstSequenceNumber
- The sequence number of the first excepted event entryprotected abstract Stream<? extends TrackedEventData<?>> readEventData(TrackingToken trackingToken, boolean mayBlock)
Stream
containing all serialized event data entries in the event storage that have a
TrackingToken
greater than the given trackingToken
. Event entries in the stream should be ordered
by tracking token. If the trackingToken
is null
a stream containing all events should be
returned.
If the end of the stream is reached and mayBlock
is true
the stream may block to wait for new
events.
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.protected abstract Stream<? extends DomainEventData<?>> readSnapshotData(String aggregateIdentifier)
aggregateIdentifier
if 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.
aggregateIdentifier
- The aggregate identifier to fetch a snapshot forpublic Serializer getSnapshotSerializer()
public Serializer getEventSerializer()
Copyright © 2010–2022. All rights reserved.