Interface ConsistencyMarker

All Known Implementing Classes:
AbstractConsistencyMarker, AggregateBasedConsistencyMarker, GlobalIndexConsistencyMarker

public interface ConsistencyMarker
Interface representing a point in an Event Stream up to where certain state has been made up-to-date. Typically, consistency markers are provided by operations on an event stream that provide events for event sourcing purposes.

Consistency Markers are used to identify the expected position new events should be inserted at, in order to avoid conflicts. If the actual insert position doesn't match the position described in this ConsistencyMarker, there may have been a concurrency conflict.

Since:
5.0.0
Author:
Allard Buijze, Steven van Beelen, Milan Savic, Sara Pellegrini, Michal Negacz, Marco Amann
  • Field Details

    • RESOURCE_KEY

      static final Context.ResourceKey<ConsistencyMarker> RESOURCE_KEY
      The ResourceKey under which consistency markers are stored in a Context.
      See Also:
    • ORIGIN

      static final ConsistencyMarker ORIGIN
      The consistency marker representing the start of an event stream. Effectively any event present in an event store would represent a conflict with this marker.
    • INFINITY

      static final ConsistencyMarker INFINITY
      The consistency marker representing the end of an event stream. Effectively no event present in an event store would represent a conflict with this marker.
  • Method Details

    • lowerBound

      ConsistencyMarker lowerBound(@Nonnull ConsistencyMarker other)
      Returns a ConsistencyMarker that represents the lower bound of this and given other markers. Effectively, this means that any events whose position in the event stream is beyond either this or the other marker, will also be beyond the returned marker.
      Parameters:
      other - The other marker to create the lower bound for
      Returns:
      a ConsistencyMarker that represents the lower bound of two other markers
    • upperBound

      ConsistencyMarker upperBound(@Nonnull ConsistencyMarker other)
      Returns a ConsistencyMarker that represents the upper bound of this and given other markers. Effectively, this means that only events whose position in the event stream is beyond both this and the other marker, will also be beyond the returned marker.
      Parameters:
      other - The other marker to create the upper bound for
      Returns:
      a ConsistencyMarker that represents the upper bound of two other markers
    • position

      Position position()
      Reduces this consistency marker to a single position if possible.
      Returns:
      a Position, never null
      Throws:
      IllegalStateException - if the marker could not be reduced to a single position
    • addToContext

      static Context addToContext(@Nonnull Context context, @Nonnull ConsistencyMarker consistencyMarker)
      Adds the given consistencyMarker to the given context using the RESOURCE_KEY.
      Parameters:
      context - The Context to add the given token to.
      consistencyMarker - The consistencyMarker to add to the given context using the RESOURCE_KEY.
      Returns:
      The given context with the given consistencyMarker attached to it.