Class StorageEngineBackedEventStore
- All Implemented Interfaces:
DescribableComponent,EventStore,SubscribableEventSource,EventBus,EventSink,StreamableEventSource,TrackingTokenSource
EventStore implementation which uses an EventStorageEngine as its storage solution.- Since:
- 3.0.0
- Author:
- Allard Buijze, Rene de Waele, Steven van Beelen
-
Constructor Summary
ConstructorsConstructorDescriptionStorageEngineBackedEventStore(EventStorageEngine eventStorageEngine, EventBus eventBus, TagResolver tagResolver) Constructs aSimpleEventStoreusing the giveneventStorageEngineto starttransactionsandwith.invalid reference
open event streams -
Method Summary
Modifier and TypeMethodDescriptionvoiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.firstToken(ProcessingContext context) Creates aTrackingTokenrepresenting the first position of theevent stream.latestToken(ProcessingContext context) Creates aTrackingTokenrepresenting the latest position, thus pointing at the next event of theevent stream.open(StreamingCondition condition, ProcessingContext context) publish(ProcessingContext context, List<EventMessage> events) Publishes the giveneventswithin the givencontext, when present.subscribe(BiFunction<List<? extends EventMessage>, ProcessingContext, CompletableFuture<?>> eventsBatchConsumer) Subscribe the giveneventsBatchConsumerto this event source.tokenAt(Instant at, ProcessingContext context) transaction(ProcessingContext processingContext) Retrieves thetransaction for appending eventsfor the givenprocessingContext.
-
Constructor Details
-
StorageEngineBackedEventStore
public StorageEngineBackedEventStore(@Nonnull EventStorageEngine eventStorageEngine, @Nonnull EventBus eventBus, @Nonnull TagResolver tagResolver) Constructs aSimpleEventStoreusing the giveneventStorageEngineto starttransactionsandwith.invalid reference
open event streams- Parameters:
eventStorageEngine- TheEventStorageEngineused to starttransactionsandwith.invalid reference
open event streamseventBus- TheEventBusused to publish events to the subscribers of the event store.tagResolver- TheTagResolverused to resolve tags during appending events in theEventStoreTransaction.
-
-
Method Details
-
transaction
Description copied from interface:EventStoreRetrieves thetransaction for appending eventsfor the givenprocessingContext. If no transaction is available, a new, empty transaction is created.- Specified by:
transactionin interfaceEventStore- Parameters:
processingContext- The context for which to retrieve theEventStoreTransaction.- Returns:
- The
EventStoreTransaction, existing or newly created, for the givenprocessingContext.
-
publish
public CompletableFuture<Void> publish(@Nullable ProcessingContext context, @Nonnull List<EventMessage> events) Description copied from interface:EventSinkPublishes the giveneventswithin the givencontext, when present.When present, the
post invocationphase is used to publish theevents. As a consequence, the resultingCompletableFuturecompletes when theeventsare staged in that phase.When no
ProcessingContextis provided, implementers of this interface may choose to create aProcessingContextwhen necessary.- Specified by:
publishin interfaceEventSink- Parameters:
context- The processing context, if any, to publish the giveneventsin.events- Theeventsto publish in this sink.- Returns:
- A
CompletableFutureofVoid. When this completes and a non-nullcontextwas given, this means theeventshave been successfully staged. When a nullcontextwas provided, successful completion of this future means theeventswhere published.
-
firstToken
Description copied from interface:TrackingTokenSourceCreates aTrackingTokenrepresenting the first position of theevent stream.As the retrieved token represents the point from which to
the event stream, the first event to be streamed when opening is the one right after the returned token.invalid reference
openSubsequent invocation of this method will yield the same result, unless the stream's initial values are deleted.
- Specified by:
firstTokenin interfaceTrackingTokenSource- Parameters:
context- The currentProcessingContext, if any.- Returns:
- A
CompletableFutureof aTrackingTokenrepresenting the first event of theevent stream.
-
latestToken
Description copied from interface:TrackingTokenSourceCreates aTrackingTokenrepresenting the latest position, thus pointing at the next event of theevent stream.As the retrieved token represents the point from which to
the event stream, the first event to be streamed when opening is the one right after the returned token.invalid reference
openSince the
event streamof this source is theoretically infinite, subsequent invocation of this operation typically return a different token. Only if thisStreamableEventSourceis idle, will severallatestToken()invocations result in the sameTrackingToken.- Specified by:
latestTokenin interfaceTrackingTokenSource- Parameters:
context- The currentProcessingContext, if any.- Returns:
- A
CompletableFutureof aTrackingTokenrepresenting the latest event, thus pointing at the next event of theevent stream.
-
tokenAt
public CompletableFuture<TrackingToken> tokenAt(@Nonnull Instant at, @Nullable ProcessingContext context) Description copied from interface:TrackingTokenSourceCreates aTrackingTokentracking alleventsafter the givenatfrom anevent stream.When there is an
EventMessageexactly at the givendateTime, it will be tracked too.- Specified by:
tokenAtin interfaceTrackingTokenSource- Parameters:
at- TheInstantdetermining how theTrackingTokenshould be created. The returned token points at very first event before thisInstant.context- The currentProcessingContext, if any.- Returns:
- A
CompletableFutureofTrackingTokenpointing at the very first event before the givenatof theevent stream.
-
open
public MessageStream<EventMessage> open(@Nonnull StreamingCondition condition, @Nullable ProcessingContext context) Description copied from interface:StreamableEventSourceOpen anevent streamcontaining alleventsmatching the givencondition.To retrieve the
positionof the returned events, theTrackingToken.fromContext(Context)operation should be used by providing the entireMessageStream.Entrywrapping the returned events.Note that the returned stream is infinite, so beware of applying terminal operations to the returned stream.
When all events are of interest during streaming, then use
EventCriteria.havingAnyTag()as the condition criteria.- Specified by:
openin interfaceStreamableEventSource- Parameters:
condition- TheStreamingConditiondefining thestarting positionof the stream andevent criteriato filter the stream with.context- The currentProcessingContext, if any.- Returns:
- An
event streammatching the givencondition.
-
describeTo
Description copied from interface:DescribableComponentDescribe the properties ofthis DescribableComponentwith the givendescriptor.Components should call the appropriate
describePropertymethods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.Best Practices: As a general rule, all relevant fields of a
DescribableComponentimplementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing thedescribeTomethod, who should focus on providing information that is useful for understanding the component's configuration and state.Example implementation:
public void describeTo(ComponentDescriptor descriptor) { descriptor.describeProperty("name", this.name); descriptor.describeProperty("enabled", this.enabled); descriptor.describeProperty("configuration", this.configuration); // A nested component descriptor.describeProperty("handlers", this.eventHandlers); // A collection }- Specified by:
describeToin interfaceDescribableComponent- Parameters:
descriptor- The component descriptor to describethis DescribableComponentn its properties in.
-
subscribe
public Registration subscribe(@Nonnull BiFunction<List<? extends EventMessage>, ProcessingContext, CompletableFuture<?>> eventsBatchConsumer) Description copied from interface:SubscribableEventSourceSubscribe the giveneventsBatchConsumerto this event source. When subscribed, it will receive all events published to this source since the subscription.If the given
eventsBatchConsumeris already subscribed, nothing happens.Note on
ProcessingContext: TheProcessingContextparameter passed to the consumer may benull. Whennull, it is the responsibility of the registeredeventsBatchConsumerto create an appropriateProcessingContextas needed for processing the events.- Specified by:
subscribein interfaceSubscribableEventSource- Parameters:
eventsBatchConsumer- The event batches consumer to subscribe.- Returns:
- A
Registrationhandle to unsubscribe theeventsBatchConsumer. When unsubscribed, it will no longer receive events.
-