Interface DomainEventStream

All Superinterfaces:
Iterator<DomainEventMessage<?>>
All Known Implementing Classes:
ConcatenatingDomainEventStream, FilteringDomainEventStream, IteratorBackedDomainEventStream

public interface DomainEventStream extends Iterator<DomainEventMessage<?>>
The DomainEventStream represents a stream of historical events published by an Aggregate. The order of events in this stream must represent the actual chronological order in which the events happened. A DomainEventStream may provide access to all events (from the first to the most recent) or any subset of these.
Author:
Rene de Waele
  • Method Details

    • of

      static DomainEventStream of(Stream<? extends DomainEventMessage<?>> stream, Supplier<Long> sequenceNumberSupplier)
      Create a new DomainEventStream with events obtained from the given stream.
      Parameters:
      stream - Stream that serves as a source of events in the resulting DomainEventStream
      sequenceNumberSupplier - supplier of the sequence number of the last used upstream event entry
      Returns:
      A DomainEventStream containing all events contained in the stream
    • of

      static DomainEventStream of(Stream<? extends DomainEventMessage<?>> stream)
      Create a new DomainEventStream with events obtained from the given stream.
      Parameters:
      stream - Stream that serves as a source of events in the resulting DomainEventStream
      Returns:
      A DomainEventStream containing all events contained in the stream
    • empty

      static DomainEventStream empty()
      Create an empty DomainEventStream.
      Returns:
      A DomainEventStream containing no events
    • of

      static DomainEventStream of(DomainEventMessage<?> event)
      Create a new DomainEventStream containing only the given event.
      Parameters:
      event - The event to add to the resulting DomainEventStream
      Returns:
      A DomainEventStream consisting of only the given event
    • of

      static DomainEventStream of(DomainEventMessage<?>... events)
      Create a new DomainEventStream from the given events.
      Parameters:
      events - Events to add to the resulting DomainEventStream
      Returns:
      A DomainEventStream consisting of all given events
    • of

      static DomainEventStream of(List<? extends DomainEventMessage<?>> list)
      Create a new DomainEventStream with events obtained from the given list.
      Parameters:
      list - list that serves as a source of events in the resulting DomainEventStream
      Returns:
      A DomainEventStream containing all events returned by the list
    • concat

      Concatenate two DomainEventStreams. In the resulting stream events from stream a will be followed by events from stream b.
      Parameters:
      a - The first stream
      b - The second stream that will follow the first stream
      Returns:
      A concatenation of stream a and b
    • filter

      default DomainEventStream filter(Predicate<? super DomainEventMessage<?>> filter)
      Returns a stream that provides the items of this stream that match the given filter.
      Parameters:
      filter - The filter to apply to the stream
      Returns:
      A filtered version of this stream
    • hasNext

      boolean hasNext()
      Returns true if the stream has more events, meaning that a call to next() will not result in an exception. If a call to this method returns false, there is no guarantee about the result of a consecutive call to next()
      Specified by:
      hasNext in interface Iterator<DomainEventMessage<?>>
      Returns:
      true if the stream contains more events.
    • next

      Returns the next events in the stream, if available. Use hasNext() to obtain a guarantee about the availability of any next event. Each call to next() will forward the pointer to the next event in the stream.

      If the pointer has reached the end of the stream, the behavior of this method is undefined. It could either return null, or throw an exception, depending on the actual implementation. Use hasNext() to confirm the existence of elements after the current pointer.

      Specified by:
      next in interface Iterator<DomainEventMessage<?>>
      Returns:
      the next event in the stream.
    • peek

      Returns the next events in the stream, if available, without moving the pointer forward. Hence, a call to next() will return the same event as a call to peek(). Use hasNext() to obtain a guarantee about the availability of any next event.

      If the pointer has reached the end of the stream, the behavior of this method is undefined. It could either return null, or throw an exception, depending on the actual implementation. Use hasNext() to confirm the existence of elements after the current pointer.

      Returns:
      the next event in the stream.
    • getLastSequenceNumber

      Long getLastSequenceNumber()
      Get the highest known sequence number in the upstream event entry stream. Note that, as result of upcasting it is possible that the last event in this stream has a lower sequence number than that returned by this method.

      To get the highest absolute sequence number of the underlying event entry stream make sure to iterate over all elements in the stream before calling this method.

      If the stream is empty this method returns null.

      Returns:
      the sequence number of the last known upstream event entry
    • remove

      default void remove()
      Specified by:
      remove in interface Iterator<DomainEventMessage<?>>
    • asStream

      default Stream<? extends DomainEventMessage<?>> asStream()
      Returns this DomainEventStream as a Stream of DomainEventMessages. Note that the returned Stream will start at the current position of the DomainEventStream.

      Note that iterating over the returned Stream may affect this DomainEventStream and vice versa. It is therefore not recommended to use this DomainEventStream after invoking this method.

      Returns:
      This DomainEventStream as a Stream of event messages