Class StorageEngineBackedEventStore

java.lang.Object
org.axonframework.eventsourcing.eventstore.StorageEngineBackedEventStore
All Implemented Interfaces:
DescribableComponent, EventStore, SubscribableEventSource, EventBus, EventSink, StreamableEventSource, TrackingTokenSource

public class StorageEngineBackedEventStore extends Object implements EventStore
An EventStore implementation which uses an EventStorageEngine as its storage solution.
Since:
3.0.0
Author:
Allard Buijze, Rene de Waele, Steven van Beelen
  • Constructor Details

    • StorageEngineBackedEventStore

      public StorageEngineBackedEventStore(@Nonnull EventStorageEngine eventStorageEngine, @Nonnull EventBus eventBus, @Nonnull TagResolver tagResolver)
      Constructs a SimpleEventStore using the given eventStorageEngine to start transactions and
      invalid reference
      open event streams
      with.
      Parameters:
      eventStorageEngine - The EventStorageEngine used to start transactions and
      invalid reference
      open event streams
      with.
      eventBus - The EventBus used to publish events to the subscribers of the event store.
      tagResolver - The TagResolver used to resolve tags during appending events in the EventStoreTransaction.
  • Method Details

    • transaction

      public EventStoreTransaction transaction(@Nonnull ProcessingContext processingContext)
      Description copied from interface: EventStore
      Retrieves the transaction for appending events for the given processingContext. If no transaction is available, a new, empty transaction is created.
      Specified by:
      transaction in interface EventStore
      Parameters:
      processingContext - The context for which to retrieve the EventStoreTransaction.
      Returns:
      The EventStoreTransaction, existing or newly created, for the given processingContext.
    • publish

      public CompletableFuture<Void> publish(@Nullable ProcessingContext context, @Nonnull List<EventMessage> events)
      Description copied from interface: EventSink
      Publishes the given events within the given context, when present.

      When present, the post invocation phase is used to publish the events. As a consequence, the resulting CompletableFuture completes when the events are staged in that phase.

      When no ProcessingContext is provided, implementers of this interface may choose to create a ProcessingContext when necessary.

      Specified by:
      publish in interface EventSink
      Parameters:
      context - The processing context, if any, to publish the given events in.
      events - The events to publish in this sink.
      Returns:
      A CompletableFuture of Void. When this completes and a non-null context was given, this means the events have been successfully staged. When a null context was provided, successful completion of this future means the events where published.
    • firstToken

      public CompletableFuture<TrackingToken> firstToken(@Nullable ProcessingContext context)
      Description copied from interface: TrackingTokenSource
      Creates a TrackingToken representing the first position of the event stream.

      As the retrieved token represents the point from which to

      invalid reference
      open
      the event stream, the first event to be streamed when opening is the one right after the returned token.

      Subsequent invocation of this method will yield the same result, unless the stream's initial values are deleted.

      Specified by:
      firstToken in interface TrackingTokenSource
      Parameters:
      context - The current ProcessingContext, if any.
      Returns:
      A CompletableFuture of a TrackingToken representing the first event of the event stream.
    • latestToken

      public CompletableFuture<TrackingToken> latestToken(@Nullable ProcessingContext context)
      Description copied from interface: TrackingTokenSource
      Creates a TrackingToken representing the latest position, thus pointing at the next event of the event stream.

      As the retrieved token represents the point from which to

      invalid reference
      open
      the event stream, the first event to be streamed when opening is the one right after the returned token.

      Since the event stream of this source is theoretically infinite, subsequent invocation of this operation typically return a different token. Only if this StreamableEventSource is idle, will several latestToken() invocations result in the same TrackingToken.

      Specified by:
      latestToken in interface TrackingTokenSource
      Parameters:
      context - The current ProcessingContext, if any.
      Returns:
      A CompletableFuture of a TrackingToken representing the latest event, thus pointing at the next event of the event stream.
    • tokenAt

      public CompletableFuture<TrackingToken> tokenAt(@Nonnull Instant at, @Nullable ProcessingContext context)
      Description copied from interface: TrackingTokenSource
      Creates a TrackingToken tracking all events after the given at from an event stream.

      When there is an EventMessage exactly at the given dateTime, it will be tracked too.

      Specified by:
      tokenAt in interface TrackingTokenSource
      Parameters:
      at - The Instant determining how the TrackingToken should be created. The returned token points at very first event before this Instant.
      context - The current ProcessingContext, if any.
      Returns:
      A CompletableFuture of TrackingToken pointing at the very first event before the given at of the event stream.
    • open

      public MessageStream<EventMessage> open(@Nonnull StreamingCondition condition, @Nullable ProcessingContext context)
      Description copied from interface: StreamableEventSource
      Open an event stream containing all events matching the given condition.

      To retrieve the position of the returned events, the TrackingToken.fromContext(Context) operation should be used by providing the entire MessageStream.Entry wrapping 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:
      open in interface StreamableEventSource
      Parameters:
      condition - The StreamingCondition defining the starting position of the stream and event criteria to filter the stream with.
      context - The current ProcessingContext, if any.
      Returns:
      An event stream matching the given condition.
    • describeTo

      public void describeTo(@Nonnull ComponentDescriptor descriptor)
      Description copied from interface: DescribableComponent
      Describe the properties of this DescribableComponent with the given descriptor.

      Components should call the appropriate describeProperty methods 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 DescribableComponent implementation 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 the describeTo method, 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:
      describeTo in interface DescribableComponent
      Parameters:
      descriptor - The component descriptor to describe this DescribableComponentn its properties in.
    • subscribe

      public Registration subscribe(@Nonnull BiFunction<List<? extends EventMessage>,ProcessingContext,CompletableFuture<?>> eventsBatchConsumer)
      Description copied from interface: SubscribableEventSource
      Subscribe the given eventsBatchConsumer to this event source. When subscribed, it will receive all events published to this source since the subscription.

      If the given eventsBatchConsumer is already subscribed, nothing happens.

      Note on ProcessingContext: The ProcessingContext parameter passed to the consumer may be null. When null, it is the responsibility of the registered eventsBatchConsumer to create an appropriate ProcessingContext as needed for processing the events.

      Specified by:
      subscribe in interface SubscribableEventSource
      Parameters:
      eventsBatchConsumer - The event batches consumer to subscribe.
      Returns:
      A Registration handle to unsubscribe the eventsBatchConsumer. When unsubscribed, it will no longer receive events.