Interface SignalListener<T>
- All Known Implementing Classes:
DefaultSignalListener
Flux or Mono signals.
This is similar to the "side effect" operators in Flux and Mono, but in a single listener class.
SignalListener are created by a SignalListenerFactory, which is tied to a particular Publisher.
Each time a new Subscriber subscribes to that Publisher, the factory creates an associated SignalListener.
Both publisher-to-subscriber events and subscription events are handled. Methods are closer to the side-effect doOnXxx operators
than to Subscriber and Subscription methods, in order to avoid misconstruing this for an actual Reactive Streams
implementation. The actual downstream Subscriber and upstream Subscription are intentionally not exposed
to avoid any influence on the observed sequence.
- Author:
- Simon Baslé
-
Method Summary
Modifier and TypeMethodDescriptiondefault ContextaddToContext(Context originalContext) In some cases, the tap operation should alter theContextexposed by the operator in order to store additional data.voidHandle graceful onComplete sequence termination, after onComplete has been propagated downstream.voiddoAfterError(Throwable error) Handle onError sequence termination after onError has been propagated downstream.voiddoFinally(SignalType terminationType) Handle terminal signals after the signals have been propagated, as the final step.voiddoFirst()Handle the very beginning of theSubscriber-Publisherinteraction.voidHandle the downstream cancelling its currently observedSubscription.voidHandle graceful onComplete sequence termination.voidHandle onError sequence termination.voiddoOnFusion(int negotiatedFusion) Handle the negotiation of fusion between twoFuseableoperators.voidHandle malformedSubscriber.onComplete(), which means the sequence has already terminated viaSubscriber.onComplete()orSubscriber.onError(Throwable).voiddoOnMalformedOnError(Throwable error) Handle malformedSubscriber.onError(Throwable), which means the sequence has already terminated viaSubscriber.onComplete()orSubscriber.onError(Throwable).voiddoOnMalformedOnNext(T value) Handle malformedSubscriber.onNext(Object), which are onNext happening after the sequence has already terminated viaSubscriber.onComplete()orSubscriber.onError(Throwable).voidHandle a new value emission from the source.voiddoOnRequest(long requested) Handle a new request made by the downstream, exposing the demand.voidHandle the fact that the upstreamPublisheracknowledgedSubscription.voidhandleListenerError(Throwable listenerError) A special handler for exceptions thrown from all the other handlers.
-
Method Details
-
doFirst
Handle the very beginning of theSubscriber-Publisherinteraction. This handler is invoked right before subscribing to the parentPublisher, as a downstreamSubscriberhas calledPublisher.subscribe(Subscriber).Once the
Publisherhas acknowledged with aSubscription, thedoOnSubscription()handler will be invoked before thatSubscriptionis passed down.- Throws:
Throwable- See Also:
-
doFinally
Handle terminal signals after the signals have been propagated, as the final step. OnlySignalType.ON_COMPLETE,SignalType.ON_ERRORorSignalType.CANCELcan be passed. This handler is invoked AFTER the terminal signal has been propagated, and if relevant AFTER thedoAfterComplete()ordoAfterError(Throwable)events. If any doOnXxx handler throws, this handler is NOT invoked (seehandleListenerError(Throwable)instead).- Throws:
Throwable- See Also:
-
doOnSubscription
Handle the fact that the upstreamPublisheracknowledgedSubscription. TheSubscriptionis intentionally not exposed in order to avoid manipulation by the observer.While
doFirst()is invoked right as the downstreamSubscriberis registered, this method is invoked as the upstream answers back with aSubscription(and before that sameSubscriptionis passed downstream). -
doOnFusion
Handle the negotiation of fusion between twoFuseableoperators. As the downstream operator requests fusion, the upstream answers back with the compatible level of fusion it can handle. ThisnegotiatedFusioncode is passed to this handler right before it is propagated downstream.- Parameters:
negotiatedFusion- the final fusion mode negotiated by the upstream operator in response to a fusion request from downstream- Throws:
Throwable
-
doOnRequest
Handle a new request made by the downstream, exposing the demand.This is invoked before the request is propagated upstream.
- Parameters:
requested- the downstream demand- Throws:
Throwable
-
doOnCancel
Handle the downstream cancelling its currently observedSubscription.This handler is invoked before propagating the cancellation upstream, while
doFinally(SignalType)is invoked right after the cancellation has been propagated upstream.- Throws:
Throwable- See Also:
-
doOnNext
Handle a new value emission from the source.This handler is invoked before propagating the value downstream.
- Parameters:
value- the emitted value- Throws:
Throwable
-
doOnComplete
Handle graceful onComplete sequence termination.This handler is invoked before propagating the completion downstream, while both
doAfterComplete()anddoFinally(SignalType)are invoked after.- Throws:
Throwable- See Also:
-
doOnError
Handle onError sequence termination.This handler is invoked before propagating the error downstream, while both
doAfterError(Throwable)anddoFinally(SignalType)are invoked after.- Parameters:
error- the exception that terminated the sequence- Throws:
Throwable- See Also:
-
doAfterComplete
Handle graceful onComplete sequence termination, after onComplete has been propagated downstream.This handler is invoked after propagating the completion downstream, similar to
doFinally(SignalType)and unlikedoOnComplete().- Throws:
Throwable
-
doAfterError
Handle onError sequence termination after onError has been propagated downstream.This handler is invoked after propagating the error downstream, similar to
doFinally(SignalType)and unlikedoOnError(Throwable).- Parameters:
error- the exception that terminated the sequence- Throws:
Throwable
-
doOnMalformedOnNext
Handle malformedSubscriber.onNext(Object), which are onNext happening after the sequence has already terminated viaSubscriber.onComplete()orSubscriber.onError(Throwable). Note that after this handler is invoked, the value is automaticallydropped.If this handler fails with an exception, that exception is
droppedbefore the value is also dropped.- Parameters:
value- the value for which an emission was attempted (which will be automatically dropped afterwards)- Throws:
Throwable
-
doOnMalformedOnError
Handle malformedSubscriber.onError(Throwable), which means the sequence has already terminated viaSubscriber.onComplete()orSubscriber.onError(Throwable). Note that after this handler is invoked, the exception is automaticallydropped.If this handler fails with an exception, that exception is
droppedbefore the original onError exception is also dropped.- Parameters:
error- the extraneous exception (which will be automatically dropped afterwards)- Throws:
Throwable
-
doOnMalformedOnComplete
Handle malformedSubscriber.onComplete(), which means the sequence has already terminated viaSubscriber.onComplete()orSubscriber.onError(Throwable).If this handler fails with an exception, that exception is
dropped.- Throws:
Throwable
-
handleListenerError
A special handler for exceptions thrown from all the other handlers. This method MUST return normally, i.e. it MUST NOT throw. When aSignalListenerhandler fails, callers are expected to first invoke this method then to propagate thelistenerErrordownstream if that is possible, terminating the original sequence with the listenerError.Typically, this special handler is intended for a last chance at processing the error despite the fact that
doFinally(SignalType)is not triggered on handler errors. For example, recording the error in a metrics backend or cleaning up state that would otherwise be cleaned up bydoFinally(SignalType).- Parameters:
listenerError- the exception thrown from aSignalListenerhandler method
-
addToContext
In some cases, the tap operation should alter theContextexposed by the operator in order to store additional data. This method is invoked when the tap subscriber is created, which is between the invocation ofdoFirst()and the invocation ofdoOnSubscription(). Generally, only addition of new keys should be performed on the downstream originalContext. Extra care should be exercised if any pre-existing key is to be removed or replaced.
-