Class BatchingEventStorageEngine
java.lang.Object
org.axonframework.eventsourcing.eventstore.AbstractEventStorageEngine
org.axonframework.eventsourcing.eventstore.BatchingEventStorageEngine
- All Implemented Interfaces:
EventStorageEngine
- Direct Known Subclasses:
JdbcEventStorageEngine,JpaEventStorageEngine,JpaEventStorageEngine
AbstractEventStorageEngine implementation that fetches events in batches from the backing database.- Since:
- 3.0
- Author:
- Rene de Waele
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAbstract Builder class to instantiate aBatchingEventStorageEngine. -
Field Summary
Fields inherited from class org.axonframework.eventsourcing.eventstore.AbstractEventStorageEngine
upcasterChain -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInstantiate aBatchingEventStorageEnginebased on the fields contained in theBatchingEventStorageEngine.Builder. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the maximum number of event entries to be fetched per batch.protected abstract List<? extends DomainEventData<?>> fetchDomainEvents(String aggregateIdentifier, long firstSequenceNumber, int batchSize) Returns a batch of events published by an aggregate with givenaggregateIdentifier.protected booleanSpecifies whether thereadEventData(String, long)should proceed fetching events for an aggregate until an empty batch is returned.protected abstract List<? extends TrackedEventData<?>> fetchTrackedEvents(TrackingToken lastToken, int batchSize) Returns a batch of serialized event data entries in the event storage that have aTrackingTokengreater than the givenlastToken.protected Stream<? extends DomainEventData<?>> readEventData(String identifier, long firstSequenceNumber) Returns aStreamof serialized event data entries for an aggregate with givenidentifier.protected Stream<? extends TrackedEventData<?>> readEventData(TrackingToken trackingToken, boolean mayBlock) Returns a globalStreamcontaining all serialized event data entries in the event storage that have aTrackingTokengreater than the giventrackingToken.Methods inherited from class org.axonframework.eventsourcing.eventstore.AbstractEventStorageEngine
appendEvents, appendEvents, getEventSerializer, getSnapshotSerializer, handlePersistenceException, readEvents, readEvents, readSnapshot, readSnapshotData, storeSnapshot, storeSnapshotMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.eventsourcing.eventstore.EventStorageEngine
appendEvents, createHeadToken, createTailToken, createTokenAt, lastSequenceNumberFor, readEvents
-
Constructor Details
-
BatchingEventStorageEngine
Instantiate aBatchingEventStorageEnginebased on the fields contained in theBatchingEventStorageEngine.Builder.Will assert that the event and snapshot
Serializerare notnull, and will throw anAxonConfigurationExceptionif any of them isnull.- Parameters:
builder- theBatchingEventStorageEngine.Builderused to instantiate aBatchingEventStorageEngineinstance
-
-
Method Details
-
fetchTrackedEvents
protected abstract List<? extends TrackedEventData<?>> fetchTrackedEvents(TrackingToken lastToken, int batchSize) Returns a batch of serialized event data entries in the event storage that have aTrackingTokengreater than the givenlastToken. Event entries in the stream should be ordered by tracking token. If thelastTokenisnulla stream containing all events should be returned.Only if the returned List is empty the event storage assumes that the backing database holds no further applicable entries.
- Parameters:
lastToken- Object describing the global index of the last processed event ornullto create a stream of all events in the storebatchSize- The maximum number of events that should be returned- Returns:
- A batch of tracked event messages stored since the given tracking token
-
fetchDomainEvents
protected abstract List<? extends DomainEventData<?>> fetchDomainEvents(String aggregateIdentifier, long firstSequenceNumber, int batchSize) Returns a batch of events published by an aggregate with givenaggregateIdentifier. The sequence numbers in the returned batch should be ordered by sequence number. The first event in the batch should have a sequence number equal to or larger than givenfirstSequenceNumber. Implementations should make sure the returned batch does not contain gaps between events due to uncommitted storage transactions. If the returned number of entries is smaller than the givenbatchSizeit is assumed that the storage holds no further applicable entries. Implementations for which this is not always the case should overridefetchForAggregateUntilEmpty()to returntrueand preferably configure a betterBatchingEventStorageEngine.Builder.finalAggregateBatchPredicate(Predicate)to provide a better heuristic for detecting the last batch in a stream.- Parameters:
aggregateIdentifier- The identifier of the aggregate to open a stream forfirstSequenceNumber- The sequence number of the first excepted event entrybatchSize- The maximum number of events that should be returned- Returns:
- a batch of serialized event entries for the given aggregate
-
fetchForAggregateUntilEmpty
protected boolean fetchForAggregateUntilEmpty()Specifies whether thereadEventData(String, long)should proceed fetching events for an aggregate until an empty batch is returned. Defaults tofalse, as Aggregate event batches typically do not have gaps in them.- Returns:
- a
booleanspecifying whetherreadEventData(String, long)should proceed fetching events for an aggregate until an empty batch is returned
-
readEventData
protected Stream<? extends DomainEventData<?>> readEventData(String identifier, long firstSequenceNumber) Description copied from class:AbstractEventStorageEngineReturns aStreamof serialized event data entries for an aggregate with givenidentifier. The events should be ordered by aggregate sequence number and have a sequence number starting from the givenfirstSequenceNumber.- Specified by:
readEventDatain classAbstractEventStorageEngine- Parameters:
identifier- The identifier of the aggregate to open a stream forfirstSequenceNumber- The sequence number of the first excepted event entry- Returns:
- a Stream of serialized event entries for the given aggregate
-
readEventData
protected Stream<? extends TrackedEventData<?>> readEventData(TrackingToken trackingToken, boolean mayBlock) Returns a globalStreamcontaining all serialized event data entries in the event storage that have aTrackingTokengreater than the giventrackingToken. Event entries in the stream should be ordered by tracking token. If thetrackingTokenisnulla stream containing all events should be returned.If the end of the stream is reached and
mayBlockistruethe stream may block to wait for new events.This implementation produces non-blocking event streams.
- Specified by:
readEventDatain classAbstractEventStorageEngine- Parameters:
trackingToken- Object describing the global index of the last processed event ornullto create a stream of all events in the storemayBlock- Iftruethe storage engine may optionally choose to block to wait for new event messages if the end of the stream is reached.- Returns:
- A stream containing all tracked event messages stored since the given tracking token
-
batchSize
public int batchSize()Returns the maximum number of event entries to be fetched per batch.- Returns:
- the fetch batch size
-