Package org.axonframework.messaging.core
Interface AbstractMessageStream.FetchResult<T extends @Nullable MessageStream.Entry<?>>
- Type Parameters:
T- the type of value returned when available
- All Known Implementing Classes:
AbstractMessageStream.FetchResult.Completed,AbstractMessageStream.FetchResult.Error,AbstractMessageStream.FetchResult.NotReady,AbstractMessageStream.FetchResult.Value
- Enclosing class:
AbstractMessageStream<M extends Message>
public static sealed interface AbstractMessageStream.FetchResult<T extends @Nullable MessageStream.Entry<?>>
permits AbstractMessageStream.FetchResult.Value<T>, AbstractMessageStream.FetchResult.Error<T>, AbstractMessageStream.FetchResult.Completed<T>, AbstractMessageStream.FetchResult.NotReady<T>
Represents the result of attempting to fetch the next element from a
MessageStream.
A FetchResult models four distinct outcomes:
AbstractMessageStream.FetchResult.Value– an element is available and returnedAbstractMessageStream.FetchResult.Completed– no element is available and no further elements will ever arriveAbstractMessageStream.FetchResult.NotReady– no element is available at present, but more may become available laterAbstractMessageStream.FetchResult.Error– the stream has failed with an error
This abstraction allows implementations to distinguish between a stream that is temporarily out of elements and one that has been fully exhausted.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordAAbstractMessageStream.FetchResultindicating that the stream is exhausted and no further elements will be produced.static final recordAAbstractMessageStream.FetchResultrepresenting a terminal error in the stream.static final recordAAbstractMessageStream.FetchResultindicating that no element is currently available, but the stream may produce more elements in the future.static final recordAAbstractMessageStream.FetchResultcontaining a successfully fetched value. -
Method Summary
Static MethodsModifier and TypeMethodDescriptionstatic <T extends MessageStream.Entry<?>>
AbstractMessageStream.FetchResult<T> Returns aFetchResultindicating that no element is available and no further elements will be produced.static <T extends MessageStream.Entry<?>>
AbstractMessageStream.FetchResult<T> Creates aFetchResultrepresenting a producer side error.static <T extends MessageStream.Entry<?>>
AbstractMessageStream.FetchResult<T> notReady()Returns aFetchResultindicating that no element is currently available, but more elements may become available in the future.static <T extends @Nullable MessageStream.Entry<?>>
AbstractMessageStream.FetchResult<T> of(@Nullable T value) Creates aFetchResultrepresenting a successfully fetched value.static <M extends Message>
AbstractMessageStream.FetchResult<MessageStream.Entry<M>> of(MessageStream<M> delegate) Creates aFetchResultreflecting the current observable state of the givenMessageStream.
-
Method Details
-
of
static <M extends Message> AbstractMessageStream.FetchResult<MessageStream.Entry<M>> of(MessageStream<M> delegate) Creates aFetchResultreflecting the current observable state of the givenMessageStream.This method inspects the provided
delegatein a non-blocking manner and translates its state into a correspondingFetchResult:- If
MessageStream.hasNextAvailable()returnstrue, this method retrieves the next entry viaMessageStream.next()and returns aAbstractMessageStream.FetchResult.Value. - If no entry is currently available and the stream is not completed, a
AbstractMessageStream.FetchResult.NotReadyis returned. - If the stream is completed normally (i.e.,
MessageStream.error()is empty), aAbstractMessageStream.FetchResult.Completedis returned. - If the stream is completed exceptionally, a
AbstractMessageStream.FetchResult.Erroris returned containing the reported error.
This method effectively adapts a
MessageStreamto theFetchResult-based consumption model used byAbstractMessageStream.Note that this method may consume an entry from the delegate when one is available, as it invokes
MessageStream.next(). As such, it should only be used in contexts where advancing the delegate stream is intended.- Type Parameters:
M- the message type contained in the stream- Parameters:
delegate- theMessageStreamto inspect, must not benull- Returns:
- a
FetchResultrepresenting the delegate's current state - Throws:
NullPointerException- ifdelegateisnull
- If
-
of
static <T extends @Nullable MessageStream.Entry<?>> AbstractMessageStream.FetchResult<T> of(@Nullable T value) Creates aFetchResultrepresenting a successfully fetched value.- Type Parameters:
T- the entry type- Parameters:
value- the non-nullvalue- Returns:
- a
AbstractMessageStream.FetchResult.Valuecontaining the given value, nevernull
-
error
static <T extends MessageStream.Entry<?>> AbstractMessageStream.FetchResult<T> error(Throwable error) Creates aFetchResultrepresenting a producer side error.- Type Parameters:
T- the entry type- Parameters:
error- the non-nullerror- Returns:
- an
AbstractMessageStream.FetchResult.Errorrepresenting the failure, nevernull
-
completed
Returns aFetchResultindicating that no element is available and no further elements will be produced.- Type Parameters:
T- the entry type- Returns:
- a
AbstractMessageStream.FetchResult.Completedresult
-
notReady
Returns aFetchResultindicating that no element is currently available, but more elements may become available in the future.- Type Parameters:
T- the entry type- Returns:
- a
AbstractMessageStream.FetchResult.NotReadyresult
-