Interface EventStoreTransaction

All Known Implementing Classes:
DefaultEventStoreTransaction

public interface EventStoreTransaction
Interface describing the actions that can be taken on a transaction to source a model from the EventStore based on the resulting MessageStream.

Note that this transaction includes operations for source(SourcingCondition) the model as well as appending events.

Since:
5.0.0
Author:
Allard Buijze, Steven van Beelen
  • Method Details

    • source

      default MessageStream<? extends EventMessage> source(SourcingCondition condition)
      Sources a MessageStream of type EventMessage based on the given condition that can be used to rehydrate a model.

      Note that using no criteria does not make sense for sourcing, as it is not recommended to source the entire event store.

      Any EventStoreTransaction using the EventStorageEngine.source(SourcingCondition) is expected to filter the TerminalEventMessage with the ConsistencyMarker.

      Parameters:
      condition - The SourcingCondition used to retrieve the MessageStream containing the sequence of events that can rehydrate a model.
      Returns:
      The MessageStream of type EventMessage containing the event sequence complying to the given condition.
    • source

      MessageStream<? extends EventMessage> source(SourcingCondition condition, @Nullable Consumer<Position> resumePositionCallback)
      Sources a MessageStream of type EventMessage based on the given condition, optionally invoking the given resume position callback.

      The provided resumePositionCallback, if non-null, is invoked at most once and only after the returned MessageStream has been consumed completely. For most implementations, the resume position is only known when the stream reaches its terminal event. As such, the callback is guaranteed to be invoked only if the stream is fully consumed.

      If sourcing completes and no events are found, the callback will be invoked with the position specified in sourcingCondition or with a greater position. Returning a greater position allows resuming from a point that already excludes positions known to be non-matching.

      If the stream terminates with an error, is closed prematurely, or is not consumed to completion, the callback is not guaranteed to be invoked.

      The callback should not throw exceptions; doing so may result in undefined behavior.

      Note that using no criteria does not make sense for sourcing, as it is not recommended to source the entire event store.

      Any EventStoreTransaction using the EventStorageEngine.source(SourcingCondition) is expected to filter the TerminalEventMessage with the ConsistencyMarker.

      Parameters:
      condition - The SourcingCondition used to retrieve the MessageStream containing the sequence of events that can rehydrate a model.
      resumePositionCallback - An optional callback that receives the Position from which sourcing may be resumed once it becomes available; the position provided is never null.
      Returns:
      The MessageStream of type EventMessage containing the event sequence complying to the given condition.
      Since:
      5.0.3
    • appendEvent

      void appendEvent(EventMessage eventMessage)
      Appends an eventMessage to be appended to an EventStore in this transaction.
      Parameters:
      eventMessage - The EventMessage to append.
    • onAppend

      void onAppend(Consumer<EventMessage> callback)
      Registers a callback to invoke when an event is appended to this transaction.

      Each callback registration adds a new callback that is invoked on the appendEvent(EventMessage, AppendCondition) operation.

      Parameters:
      callback - A Consumer to invoke when an event is appended in this transaction.
    • appendPosition

      ConsistencyMarker appendPosition()
      Returns the position in the event store of the last appended event by this transaction.

      Will return ConsistencyMarker.ORIGIN if nothing has been appended yet.

      Returns:
      The position in the event store of the last appended event by this transaction.