public abstract class AbstractEventStorageEngine extends Object implements EventStorageEngine
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractEventStorageEngine(Serializer serializer,
EventUpcaster upcasterChain,
PersistenceExceptionResolver persistenceExceptionResolver)
Deprecated.
The constructor which supplies an additional
Serializer for
events should be used. |
protected |
AbstractEventStorageEngine(Serializer snapshotSerializer,
EventUpcaster upcasterChain,
PersistenceExceptionResolver persistenceExceptionResolver,
Serializer eventSerializer)
Initializes an EventStorageEngine with given
serializer, upcasterChain and persistenceExceptionResolver. |
protected |
AbstractEventStorageEngine(Serializer snapshotSerializer,
EventUpcaster upcasterChain,
PersistenceExceptionResolver persistenceExceptionResolver,
Serializer eventSerializer,
Predicate<? super DomainEventData<?>> snapshotFilter)
Initializes an EventStorageEngine with given
serializer, upcasterChain and persistenceExceptionResolver. |
| 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 |
getSerializer()
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 Optional<? extends DomainEventData<?>> |
readSnapshotData(String aggregateIdentifier)
Returns an optional serialized event entry 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, waitappendEvents, createHeadToken, createTailToken, createTokenAt, lastSequenceNumberFor, readEvents@Deprecated protected AbstractEventStorageEngine(Serializer serializer, EventUpcaster upcasterChain, PersistenceExceptionResolver persistenceExceptionResolver)
Serializer for
events should be used.serializer, upcasterChain and persistenceExceptionResolver.serializer - Used to serialize and deserialize event payload and metadata. If null
a new XStreamSerializer is used.upcasterChain - Allows older revisions of serialized objects to be deserialized. If null a NoOpEventUpcaster is used.persistenceExceptionResolver - Detects concurrency exceptions from the backing database. If null
persistence exceptions are not explicitly resolved.protected AbstractEventStorageEngine(Serializer snapshotSerializer, EventUpcaster upcasterChain, PersistenceExceptionResolver persistenceExceptionResolver, Serializer eventSerializer)
serializer, upcasterChain and persistenceExceptionResolver.snapshotSerializer - Used to serialize and deserialize snapshots. If null
a new XStreamSerializer is used.upcasterChain - Allows older revisions of serialized objects to be deserialized. If null a NoOpEventUpcaster is used.persistenceExceptionResolver - Detects concurrency exceptions from the backing database. If null
persistence exceptions are not explicitly resolved.eventSerializer - Used to serialize and deserialize event payload and metadata. If null
a new XStreamSerializer is used.protected AbstractEventStorageEngine(Serializer snapshotSerializer, EventUpcaster upcasterChain, PersistenceExceptionResolver persistenceExceptionResolver, Serializer eventSerializer, Predicate<? super DomainEventData<?>> snapshotFilter)
serializer, upcasterChain and persistenceExceptionResolver. The given snapshotFilter is used to define which snapshots are accepted
for this version of the application.snapshotSerializer - Used to serialize and deserialize snapshots. If null
a new XStreamSerializer is used.upcasterChain - Allows older revisions of serialized objects to be deserialized. If null a NoOpEventUpcaster is used.persistenceExceptionResolver - Detects concurrency exceptions from the backing database. If null
persistence exceptions are not explicitly resolved.eventSerializer - Used to serialize and deserialize event payload and metadata. If null
a new XStreamSerializer is used.snapshotFilter - Decides whether to use a snapshot or not. If null, every snapshot is
accepted as viable.public Stream<? extends TrackedEventMessage<?>> readEvents(TrackingToken trackingToken, boolean mayBlock)
EventStorageEnginetrackingToken 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 EventStorageEnginetrackingToken - 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)
EventStorageEngineDomainEventStream 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 EventStorageEngineaggregateIdentifier - The identifier of the aggregatefirstSequenceNumber - The expected sequence number of the first event in the returned streampublic Optional<DomainEventMessage<?>> readSnapshot(String aggregateIdentifier)
EventStorageEngineaggregateIdentifier. If the storage engine has
no snapshot event of the aggregate, an empty Optional is returned.readSnapshot in interface EventStorageEngineaggregateIdentifier - 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 EventStorageEngineevents - Events to append to the event storagepublic void storeSnapshot(DomainEventMessage<?> snapshot)
EventStorageEnginestoreSnapshot in interface EventStorageEnginesnapshot - 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 Optional<? extends DomainEventData<?>> readSnapshotData(String aggregateIdentifier)
aggregateIdentifier if the backing database
contains a snapshot of the aggregate.aggregateIdentifier - The aggregate identifier to fetch a snapshot forpublic Serializer getSerializer()
public Serializer getEventSerializer()
Copyright © 2010–2018. All rights reserved.