Interface DomainEventStream
- All Superinterfaces:
Iterator<DomainEventMessage<?>>
- All Known Implementing Classes:
ConcatenatingDomainEventStream,FilteringDomainEventStream,IteratorBackedDomainEventStream
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 Summary
Modifier and TypeMethodDescriptiondefault Stream<? extends DomainEventMessage<?>> asStream()Returns this DomainEventStream as aStreamof DomainEventMessages.static DomainEventStreamConcatenate two DomainEventStreams.static DomainEventStreamempty()Create an empty DomainEventStream.default DomainEventStreamfilter(Predicate<? super DomainEventMessage<?>> filter) Returns a stream that provides the items of this stream that match the givenfilter.Get the highest known sequence number in the upstream event entry stream.booleanhasNext()Returnstrueif the stream has more events, meaning that a call tonext()will not result in an exception.next()Returns the next events in the stream, if available.static DomainEventStreamof(List<? extends DomainEventMessage<?>> list) Create a new DomainEventStream with events obtained from the givenlist.static DomainEventStreamof(Stream<? extends DomainEventMessage<?>> stream) Create a new DomainEventStream with events obtained from the givenstream.static DomainEventStreamof(Stream<? extends DomainEventMessage<?>> stream, Supplier<Long> sequenceNumberSupplier) Create a new DomainEventStream with events obtained from the givenstream.static DomainEventStreamof(DomainEventMessage<?> event) Create a new DomainEventStream containing only the givenevent.static DomainEventStreamof(DomainEventMessage<?>... events) Create a new DomainEventStream from the givenevents.peek()Returns the next events in the stream, if available, without moving the pointer forward.default voidremove()Methods inherited from interface java.util.Iterator
forEachRemaining
-
Method Details
-
of
static DomainEventStream of(Stream<? extends DomainEventMessage<?>> stream, Supplier<Long> sequenceNumberSupplier) Create a new DomainEventStream with events obtained from the givenstream.- Parameters:
stream- Stream that serves as a source of events in the resulting DomainEventStreamsequenceNumberSupplier- supplier of the sequence number of the last used upstream event entry- Returns:
- A DomainEventStream containing all events contained in the stream
-
of
Create a new DomainEventStream with events obtained from the givenstream.- 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
Create an empty DomainEventStream.- Returns:
- A DomainEventStream containing no events
-
of
Create a new DomainEventStream containing only the givenevent.- Parameters:
event- The event to add to the resulting DomainEventStream- Returns:
- A DomainEventStream consisting of only the given event
-
of
Create a new DomainEventStream from the givenevents.- Parameters:
events- Events to add to the resulting DomainEventStream- Returns:
- A DomainEventStream consisting of all given events
-
of
Create a new DomainEventStream with events obtained from the givenlist.- 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 streamawill be followed by events from streamb.- Parameters:
a- The first streamb- The second stream that will follow the first stream- Returns:
- A concatenation of stream a and b
-
filter
Returns a stream that provides the items of this stream that match the givenfilter.- Parameters:
filter- The filter to apply to the stream- Returns:
- A filtered version of this stream
-
hasNext
boolean hasNext()Returnstrueif the stream has more events, meaning that a call tonext()will not result in an exception. If a call to this method returnsfalse, there is no guarantee about the result of a consecutive call tonext()- Specified by:
hasNextin interfaceIterator<DomainEventMessage<?>>- Returns:
trueif the stream contains more events.
-
next
DomainEventMessage<?> next()Returns the next events in the stream, if available. UsehasNext()to obtain a guarantee about the availability of any next event. Each call tonext()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 returnnull, or throw an exception, depending on the actual implementation. UsehasNext()to confirm the existence of elements after the current pointer.- Specified by:
nextin interfaceIterator<DomainEventMessage<?>>- Returns:
- the next event in the stream.
-
peek
DomainEventMessage<?> peek()Returns the next events in the stream, if available, without moving the pointer forward. Hence, a call tonext()will return the same event as a call topeek(). UsehasNext()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 returnnull, or throw an exception, depending on the actual implementation. UsehasNext()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:
removein interfaceIterator<DomainEventMessage<?>>
-
asStream
Returns this DomainEventStream as aStreamof 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
-