Class CloseCallbackMessageStream<M extends Message>
- Type Parameters:
M- The type of Message handled by this MessageStream.
- All Implemented Interfaces:
MessageStream<M>
closeHandler once the stream is closed. A stream is
considered closed when a consumer explicitly calls AbstractMessageStream.close() or when the stream is completed.
Note that when close is called on the delegate, or when the client does not attempt to consume this stream, the close handler may never be invoked, even though the stream is completed.
- Since:
- 5.0.0
- Author:
- John Hendrikx
-
Nested Class Summary
Nested classes/interfaces inherited from class org.axonframework.messaging.core.AbstractMessageStream
AbstractMessageStream.FetchResult<T extends @Nullable MessageStream.Entry<?>>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> -
Constructor Summary
ConstructorsConstructorDescriptionCloseCallbackMessageStream(MessageStream<M> delegate, Runnable closeHandler) Creates an instance of the CloseCallbackMessageStream, calling the givencloseHandleronce this stream is closed, or the givendelegatecompletes. -
Method Summary
Modifier and TypeMethodDescriptionSubtypes should override this to describe any (message stream) delegates they use for debugging purposes.protected AbstractMessageStream.FetchResult<MessageStream.Entry<M>> Attempts to fetch the next availableMessageStream.Entryfrom the underlying source.protected voidCallback invoked when the stream is about to transition to a completed state, either successfully or exceptionally.Methods inherited from class org.axonframework.messaging.core.AbstractMessageStream
close, describeFlags, error, hasNextAvailable, initialize, isCompleted, next, peek, setCallback, signalProgress, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.axonframework.messaging.core.MessageStream
cast, concatWith, filter, first, ignoreEntries, map, mapMessage, onClose, onComplete, onErrorContinue, onNext, reduce
-
Constructor Details
-
CloseCallbackMessageStream
Creates an instance of the CloseCallbackMessageStream, calling the givencloseHandleronce this stream is closed, or the givendelegatecompletes.- Parameters:
delegate- The MessageStream to wrap with the close handler invocation logiccloseHandler- The handler to invoke when the stream is closed or completed
-
-
Method Details
-
fetchNext
Description copied from class:AbstractMessageStreamAttempts to fetch the next availableMessageStream.Entryfrom the underlying source.This method is invoked by
AbstractMessageStream.next()when no previously peeked entry is available. Implementations must return aAbstractMessageStream.FetchResultdescribing the current state of the stream:AbstractMessageStream.FetchResult.Valueif an entry is immediately available,AbstractMessageStream.FetchResult.NotReadyif no entry is currently available but more may arrive later,AbstractMessageStream.FetchResult.Completedif the stream is exhausted and will produce no further entries,AbstractMessageStream.FetchResult.Errorif the stream has failed with an error.
Returning
AbstractMessageStream.FetchResult.NotReadywill transition the stream into an awaiting data state. Implementations must subsequently invokeAbstractMessageStream.signalProgress()when progress may be possible again (e.g., when new data arrives or the stream completes).Implementations must ensure that any state changes observable via this method are fully applied before invoking
AbstractMessageStream.signalProgress(). A signal that arrives before the consumer has entered the awaiting state is not replayed; correctness relies on this method returning the updated state when the consumer calls it next. SeeAbstractMessageStream.signalProgress()for the full ordering contract.This method must be non-blocking. It should return immediately with the best available information about the stream's current state.
Implementations must not attempt to complete or close the stream directly. Instead, they must return
AbstractMessageStream.FetchResult.CompletedorAbstractMessageStream.FetchResult.Errorto signal termination.If an implementation throws an exception, the stream completes exceptionally with that exception.
- Specified by:
fetchNextin classAbstractMessageStream<M extends Message>- Returns:
- a
AbstractMessageStream.FetchResultrepresenting the outcome of the fetch attempt
-
onCompleted
protected void onCompleted()Description copied from class:AbstractMessageStreamCallback invoked when the stream is about to transition to a completed state, either successfully or exceptionally. Subclasses may override this method to perform custom actions on completion.If the implementation throws an exception, the stream still completes, but it will complete with the thrown exception. If the stream was about to complete with an error, and the callback fails as well, the exception is added as a suppressed exception.
- Overrides:
onCompletedin classAbstractMessageStream<M extends Message>
-
describeDelegates
Description copied from class:AbstractMessageStreamSubtypes should override this to describe any (message stream) delegates they use for debugging purposes. This allows to visualize a chain of message streams, their states and how they are linked.If there are multiple delegates, then they should be comma separated with the active delegate prepended with an asterisk ("*").
- Overrides:
describeDelegatesin classAbstractMessageStream<M extends Message>- Returns:
- the description of delegate streams, or
nullif there are no delegates
-