public class ConcatenatingDomainEventStream extends Object implements DomainEventStream
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.
Constructor and Description |
---|
ConcatenatingDomainEventStream(Collection<DomainEventStream> streams)
Initialize the stream, concatenating the given
streams . |
ConcatenatingDomainEventStream(DomainEventStream... streams)
Initialize the stream, concatenating the given
streams . |
Modifier and Type | Method and Description |
---|---|
Long |
getLastSequenceNumber()
Get the highest known sequence number in the upstream event entry stream.
|
boolean |
hasNext()
Returns
true if the stream has more events, meaning that a call to next() will not
result in an exception. |
DomainEventMessage<?> |
next()
Returns the next events in the stream, if available.
|
DomainEventMessage<?> |
peek()
Returns the next events in the stream, if available, without moving the pointer forward.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
asStream, concat, empty, filter, of, of, of, of, of, remove
forEachRemaining
public ConcatenatingDomainEventStream(DomainEventStream... streams)
streams
.streams
- The streams providing the elements to concatenatepublic ConcatenatingDomainEventStream(Collection<DomainEventStream> streams)
streams
. The streams are consumed in the order the
collection returns them.streams
- The streams providing the elements to concatenatepublic DomainEventMessage<?> peek()
DomainEventStream
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.peek
in interface DomainEventStream
public boolean hasNext()
DomainEventStream
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()
hasNext
in interface Iterator<DomainEventMessage<?>>
hasNext
in interface DomainEventStream
true
if the stream contains more events.public DomainEventMessage<?> next()
DomainEventStream
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.next
in interface Iterator<DomainEventMessage<?>>
next
in interface DomainEventStream
public Long getLastSequenceNumber()
DomainEventStream
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
.
getLastSequenceNumber
in interface DomainEventStream
Copyright © 2010–2024. All rights reserved.