Class ConcatenatingDomainEventStream

java.lang.Object
org.axonframework.eventsourcing.eventstore.ConcatenatingDomainEventStream
All Implemented Interfaces:
Iterator<DomainEventMessage<?>>, DomainEventStream

public class ConcatenatingDomainEventStream extends Object implements DomainEventStream
DomainEventStream implementation that concatenates multiple streams, taking into account that some sequence numbers may appear in more than one stream.

Streams are consumed in the order provided, skipping events that have sequence numbers equal or lower than the last sequence number consumed from the previous stream.

This implementation is not thread safe. It should not be consumed by more than one thread at a time.

Since:
3.1.1
  • Constructor Details

    • ConcatenatingDomainEventStream

      public ConcatenatingDomainEventStream(DomainEventStream... streams)
      Initialize the stream, concatenating the given streams.
      Parameters:
      streams - The streams providing the elements to concatenate
    • ConcatenatingDomainEventStream

      public ConcatenatingDomainEventStream(Collection<DomainEventStream> streams)
      Initialize the stream, concatenating the given streams. The streams are consumed in the order the collection returns them.
      Parameters:
      streams - The streams providing the elements to concatenate
  • Method Details

    • peek

      public DomainEventMessage<?> peek()
      Description copied from interface: DomainEventStream
      Returns the next events in the stream, if available, without moving the pointer forward. Hence, a call to DomainEventStream.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 DomainEventStream.hasNext() to confirm the existence of elements after the current pointer.

      Specified by:
      peek in interface DomainEventStream
      Returns:
      the next event in the stream.
    • hasNext

      public boolean hasNext()
      Description copied from interface: DomainEventStream
      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 DomainEventStream
      Specified by:
      hasNext in interface Iterator<DomainEventMessage<?>>
      Returns:
      true if the stream contains more events.
    • next

      public DomainEventMessage<?> next()
      Description copied from interface: DomainEventStream
      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 DomainEventStream.hasNext() to confirm the existence of elements after the current pointer.

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

      public Long getLastSequenceNumber()
      Description copied from interface: DomainEventStream
      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.

      Specified by:
      getLastSequenceNumber in interface DomainEventStream
      Returns:
      the sequence number of the last known upstream event entry