public class InMemoryEventStorageEngine extends Object implements EventStorageEngine
| Constructor and Description |
|---|
InMemoryEventStorageEngine()
Initializes an InMemoryEventStorageEngine.
|
InMemoryEventStorageEngine(long offset)
Initializes an InMemoryEventStorageEngine using given
offset to initialize the tokens with. |
| Modifier and Type | Method and Description |
|---|---|
void |
appendEvents(List<? extends EventMessage<?>> events)
Append a list of events to the event storage.
|
TrackingToken |
createHeadToken()
Creates a token that is at the head of an event stream - that tracks all new events.
|
TrackingToken |
createTailToken()
Creates a token that is at the tail of an event stream - that tracks events from the beginning of time.
|
TrackingToken |
createTokenAt(Instant dateTime)
Creates a token that tracks all events after given
dateTime. |
protected GlobalSequenceTrackingToken |
nextTrackingToken()
Returns the tracking token to use for the next event to be stored.
|
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. |
void |
storeSnapshot(DomainEventMessage<?> snapshot)
Store an event that contains a snapshot of an aggregate.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitappendEvents, lastSequenceNumberFor, readEventspublic InMemoryEventStorageEngine()
public InMemoryEventStorageEngine(long offset)
offset to initialize the tokens with.offset - The value to use for the token of the first event appendedpublic void appendEvents(@Nonnull 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(@Nonnull DomainEventMessage<?> snapshot)
EventStorageEnginestoreSnapshot in interface EventStorageEnginesnapshot - The snapshot event of the aggregate that is to be storedpublic Stream<? extends TrackedEventMessage<?>> readEvents(TrackingToken trackingToken, boolean mayBlock)
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.
This implementation produces non-blocking event streams.
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(@Nonnull 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(@Nonnull 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 TrackingToken createTailToken()
EventStorageEnginecreateTailToken in interface EventStorageEnginenull is returnedpublic TrackingToken createHeadToken()
EventStorageEnginecreateHeadToken in interface EventStorageEnginenull is returnedpublic TrackingToken createTokenAt(@Nonnull Instant dateTime)
EventStorageEnginedateTime. If there is an event exactly at the given
dateTime, it will be tracked too.createTokenAt in interface EventStorageEnginedateTime - The date and time for determining criteria how the tracking token should be created. A tracking
token should point to very first event before this date and time.dateTime, if there aren't events matching this criteria null is returnedprotected GlobalSequenceTrackingToken nextTrackingToken()
Copyright © 2010–2023. All rights reserved.