Class FilteringEventStorageEngine

java.lang.Object
org.axonframework.eventsourcing.FilteringEventStorageEngine
All Implemented Interfaces:
EventStorageEngine

public class FilteringEventStorageEngine extends Object implements EventStorageEngine
Implementation of EventStorageEngine that delegates to another implementation, while filtering events as they are appended. This prevents certain events to be stored in the Event Store.
Since:
3.1
Author:
Allard Buijze
  • Constructor Details

    • FilteringEventStorageEngine

      public FilteringEventStorageEngine(EventStorageEngine delegate, Predicate<? super EventMessage<?>> filter)
      Initializes the FilteringEventStorageEngine delegating all event messages matching the given filter to the given delegate.

      Note that this only affects events stored in the StorageEngine. The EventStore will still publish these events to Subscribed event handlers. Tracking Event Processors take their events from the stored events, and will therefore not receive any events blocked by this instance.

      Parameters:
      delegate - the EventStorageEngine to store matching messages in
      filter - the predicate that event messages must match against to be stored
  • Method Details

    • appendEvents

      public void appendEvents(@Nonnull EventMessage<?>... events)
      Description copied from interface: EventStorageEngine
      Append one or more events to the event storage. Events will be appended in the order that they are offered in.

      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.

      By default this method creates a list of the offered events and then invokes EventStorageEngine.appendEvents(List).

      Specified by:
      appendEvents in interface EventStorageEngine
      Parameters:
      events - Events to append to the event storage
    • appendEvents

      public void appendEvents(@Nonnull List<? extends EventMessage<?>> events)
      Description copied from interface: EventStorageEngine
      Append a list of events to the event storage. Events will be appended in the order that they are offered in.

      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.

      Specified by:
      appendEvents in interface EventStorageEngine
      Parameters:
      events - Events to append to the event storage
    • storeSnapshot

      public void storeSnapshot(@Nonnull DomainEventMessage<?> snapshot)
      Description copied from interface: EventStorageEngine
      Store an event that contains a snapshot of an aggregate. If the event storage already contains a snapshot for the same aggregate, then it will be replaced with the given snapshot.
      Specified by:
      storeSnapshot in interface EventStorageEngine
      Parameters:
      snapshot - The snapshot event of the aggregate that is to be stored
    • readEvents

      public Stream<? extends TrackedEventMessage<?>> readEvents(TrackingToken trackingToken, boolean mayBlock)
      Description copied from interface: EventStorageEngine
      Open an event stream containing all events stored since given tracking token. The returned stream is comprised of events from aggregates as well as other application events. Pass a 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.

      Specified by:
      readEvents in interface EventStorageEngine
      Parameters:
      trackingToken - Object describing the global index of the last processed event or null to create a stream of all events in the store
      mayBlock - If true the 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
    • readEvents

      public DomainEventStream readEvents(@Nonnull String aggregateIdentifier)
      Description copied from interface: EventStorageEngine
      Get a DomainEventStream containing all events published by the aggregate with given aggregateIdentifier. By default calling this method is shorthand for an invocation of EventStorageEngine.readEvents(String, long) with a sequence number of 0.

      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.

      Specified by:
      readEvents in interface EventStorageEngine
      Parameters:
      aggregateIdentifier - The identifier of the aggregate to return an event stream for
      Returns:
      A non-blocking DomainEventStream of the given aggregate
    • readEvents

      public DomainEventStream readEvents(@Nonnull String aggregateIdentifier, long firstSequenceNumber)
      Description copied from interface: EventStorageEngine
      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.

      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.

      Specified by:
      readEvents in interface EventStorageEngine
      Parameters:
      aggregateIdentifier - The identifier of the aggregate
      firstSequenceNumber - The expected sequence number of the first event in the returned stream
      Returns:
      A non-blocking DomainEventStream of the given aggregate
    • readSnapshot

      public Optional<DomainEventMessage<?>> readSnapshot(@Nonnull String aggregateIdentifier)
      Description copied from interface: EventStorageEngine
      Try to load a snapshot event of the aggregate with given aggregateIdentifier. If the storage engine has no snapshot event of the aggregate, an empty Optional is returned.
      Specified by:
      readSnapshot in interface EventStorageEngine
      Parameters:
      aggregateIdentifier - The identifier of the aggregate
      Returns:
      An optional with a snapshot of the aggregate
    • lastSequenceNumberFor

      public Optional<Long> lastSequenceNumberFor(@Nonnull String aggregateIdentifier)
      Description copied from interface: EventStorageEngine
      Returns the last known sequence number for the given aggregateIdentifier.

      While it's recommended to use the sequence numbers from the DomainEventStream, there are cases where knowing the sequence number is required, without having read the actual events. In such case, this method is a viable alternative.

      Specified by:
      lastSequenceNumberFor in interface EventStorageEngine
      Parameters:
      aggregateIdentifier - The identifier to find the last sequence number for
      Returns:
      an optional with the highest sequence number, or an empty optional if the aggregate identifier wasn't found
    • createTailToken

      public TrackingToken createTailToken()
      Description copied from interface: EventStorageEngine
      Creates a token that is at the tail of an event stream - that tracks events from the beginning of time.
      Specified by:
      createTailToken in interface EventStorageEngine
      Returns:
      a tracking token at the tail of an event stream, if event stream is empty null is returned
    • createHeadToken

      public TrackingToken createHeadToken()
      Description copied from interface: EventStorageEngine
      Creates a token that is at the head of an event stream - that tracks all new events.
      Specified by:
      createHeadToken in interface EventStorageEngine
      Returns:
      a tracking token at the head of an event stream, if event stream is empty null is returned
    • createTokenAt

      public TrackingToken createTokenAt(@Nonnull Instant dateTime)
      Description copied from interface: EventStorageEngine
      Creates a token that tracks all events after given dateTime. If there is an event exactly at the given dateTime, it will be tracked too.
      Specified by:
      createTokenAt in interface EventStorageEngine
      Parameters:
      dateTime - 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.
      Returns:
      a tracking token at the given dateTime, if there aren't events matching this criteria null is returned