Interface MessageStream.Single<M extends Message>
- Type Parameters:
M- The type ofMessagecontained in the singularMessageStream.Entryof this stream.
- All Superinterfaces:
MessageStream<M>
- All Known Subinterfaces:
MessageStream.Empty<M>
- Enclosing interface:
MessageStream<M extends Message>
MessageStream implementation that returns at most a single result before completing.- Since:
- 5.0.0
- Author:
- Allard Buijze, Mateusz Nowak, Mitchell Herrijgers, Steven van Beelen
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.axonframework.messaging.core.MessageStream
MessageStream.Empty<M extends Message>, MessageStream.Entry<M extends Message>, MessageStream.Single<M extends Message> -
Method Summary
Modifier and TypeMethodDescriptiondefault CompletableFuture<@Nullable MessageStream.Entry<M>> Returns aCompletableFuturethat completes when this stream has been fully consumed, either normally or with an error.default <R extends Message>
MessageStream.Single<R> cast()Casts this stream to the given type.default MessageStream.Single<M> filter(Predicate<MessageStream.Entry<M>> filter) Returns a stream that will filterentriesbased on the givenfilter.default MessageStream.Single<M> first()Returns astreamthat includes only the first message ofthisstream, unless it completes without delivering any messages, in which case it completes the same way.default <RM extends Message>
MessageStream.Single<RM> map(Function<MessageStream.Entry<M>, MessageStream.Entry<RM>> mapper) default <RM extends Message>
MessageStream.Single<RM> mapMessage(Function<M, RM> mapper) default MessageStream.Single<M> onComplete(Runnable completeHandler) Returns a stream that invokes the givencompleteHandlerwhen the stream completes normally.default MessageStream.Single<M> onNext(Consumer<MessageStream.Entry<M>> onNext) Invokes the givenonNexteach time anentryis consumed from this stream.Methods inherited from interface org.axonframework.messaging.core.MessageStream
close, concatWith, error, hasNextAvailable, ignoreEntries, isCompleted, next, onClose, onErrorContinue, peek, reduce, setCallback
-
Method Details
-
first
Description copied from interface:MessageStreamReturns astreamthat includes only the first message ofthisstream, unless it completes without delivering any messages, in which case it completes the same way.When the first message is delivered, the returned stream completes normally, independently of how this stream completes. Upon consuming the first message, this stream is
MessageStream.close()immediately.- Specified by:
firstin interfaceMessageStream<M extends Message>- Returns:
- A
streamthat includes only the first message ofthisstream.
-
map
default <RM extends Message> MessageStream.Single<RM> map(Function<MessageStream.Entry<M>, MessageStream.Entry<RM>> mapper) Description copied from interface:MessageStreamReturns a stream that maps eachentryfrom this stream using givenmapperfunction into an entry carrying aMessageEntrywith aMessageof typeRM.The returned stream completes the same way
thisstream completes.- Specified by:
mapin interfaceMessageStream<M extends Message>- Type Parameters:
RM- The declared type ofMessagecontained in the returnedentry.- Parameters:
mapper- The function convertingentriesfrom this stream from entries containingmessageof typeMtoRM.- Returns:
- A stream with all
entriesmapped according to themapperfunction.
-
mapMessage
Description copied from interface:MessageStreamReturns a stream that maps eachmessagefrom theentriesin this stream using the givenmapperfunction. This maps theMessagesfrom typeMto typeRM.The returned stream completes the same way
thisstream completes.- Specified by:
mapMessagein interfaceMessageStream<M extends Message>- Type Parameters:
RM- The declared type ofMessagecontained in the returnedentry.- Parameters:
mapper- The function convertingmessagefrom theentriesin this stream from typeMtoRM.- Returns:
- A stream with all
entriesmapped according to themapperfunction.
-
filter
Description copied from interface:MessageStreamReturns a stream that will filterentriesbased on the givenfilter.- Specified by:
filterin interfaceMessageStream<M extends Message>- Parameters:
filter- TheMessageStream.Entrypredicate, that will filter out entries. Returningtruefrom this lambda will keep the entry, while returningfalsewill remove it.- Returns:
- A stream for which the
entrieshave been filtered by the givenfilter.
-
onNext
Description copied from interface:MessageStreamInvokes the givenonNexteach time anentryis consumed from this stream.Depending on the stream's implementation, the function may be invoked when the entry is provided to the
Consumer, or at the moment it's available for reading on the stream. Subscribing multiple times to the resulting stream may cause the givenonNextto be invoked more than once for an entry. -
onComplete
Description copied from interface:MessageStreamReturns a stream that invokes the givencompleteHandlerwhen the stream completes normally. Throws an exception if this stream is unbounded.- Specified by:
onCompletein interfaceMessageStream<M extends Message>- Parameters:
completeHandler- TheRunnableto invoke when the stream completes normally.- Returns:
- A stream that invokes the
completeHandlerupon normal completion.
-
cast
Description copied from interface:MessageStreamCasts this stream to the given type. This method is provided to be more flexible with generics. It is the caller's responsibility to ensure the cast is valid. Failure to do so may result inClassCastExceptionwhen reading elements. -
asCompletableFuture
Returns aCompletableFuturethat completes when this stream has been fully consumed, either normally or with an error.The future completes with the first
MessageStream.Entryobserved during stream consumption, ornullif no entries were produced before completion.This method always drives full stream execution (via
reduce), even though only the first encountered entry is retained. This is required to correctly support streams that may:- be composed via
concatWith - perform side-effect-only processing via
ignoreEntries() - defer emission until completion
As a result, this operation is not a simple "fetch first element" operation, but a terminal stream execution that observes the first entry while ensuring complete stream traversal.
- Returns:
- A
CompletableFuturecompleted with the first observedMessageStream.Entry,nullif none were produced, or completed exceptionally if the stream fails. - Throws:
UnsupportedOperationException- if this stream is unbounded
- be composed via
-