public abstract class DefaultSignalListener<T> extends Object implements SignalListener<T>
SignalListener
with all the handlers no-op.Constructor and Description |
---|
DefaultSignalListener() |
Modifier and Type | Method and Description |
---|---|
void |
doAfterComplete()
Handle graceful onComplete sequence termination, after onComplete has been propagated downstream.
|
void |
doAfterError(Throwable error)
Handle onError sequence termination after onError has been propagated downstream.
|
void |
doFinally(SignalType terminationType)
Handle terminal signals after the signals have been propagated, as the final step.
|
void |
doFirst()
Handle the very beginning of the
Subscriber -Publisher interaction. |
void |
doOnCancel()
Handle the downstream cancelling its currently observed
Subscription . |
void |
doOnComplete()
Handle graceful onComplete sequence termination.
|
void |
doOnError(Throwable error)
Handle onError sequence termination.
|
void |
doOnFusion(int negotiatedFusion)
Handle the negotiation of fusion between two
Fuseable operators. |
void |
doOnMalformedOnComplete()
Handle malformed
Subscriber.onComplete() , which means the sequence has already terminated
via Subscriber.onComplete() or Subscriber.onError(Throwable) . |
void |
doOnMalformedOnError(Throwable error)
Handle malformed
Subscriber.onError(Throwable) , which means the sequence has already terminated
via Subscriber.onComplete() or Subscriber.onError(Throwable) . |
void |
doOnMalformedOnNext(T value)
Handle malformed
Subscriber.onNext(Object) , which are onNext happening after the sequence has already terminated
via Subscriber.onComplete() or Subscriber.onError(Throwable) . |
void |
doOnNext(T value)
Handle a new value emission from the source.
|
void |
doOnRequest(long requested)
Handle a new request made by the downstream, exposing the demand.
|
void |
doOnSubscription()
Handle the fact that the upstream
Publisher acknowledged Subscription . |
protected int |
getFusionMode()
Return the fusion mode negotiated with the source:
Fuseable.SYNC and Fuseable.ASYNC ) as relevant
if some fusion was negotiated. |
void |
handleListenerError(Throwable listenerError)
A special handler for exceptions thrown from all the other handlers.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addToContext
public void doFirst() throws Throwable
SignalListener
Subscriber
-Publisher
interaction.
This handler is invoked right before subscribing to the parent Publisher
, as a downstream
Subscriber
has called Publisher.subscribe(Subscriber)
.
Once the Publisher
has acknowledged with a Subscription
, the SignalListener.doOnSubscription()
handler will be invoked before that Subscription
is passed down.
doFirst
in interface SignalListener<T>
Throwable
SignalListener.doOnSubscription()
public void doFinally(SignalType terminationType) throws Throwable
SignalListener
SignalType.ON_COMPLETE
, SignalType.ON_ERROR
or SignalType.CANCEL
can be passed.
This handler is invoked AFTER the terminal signal has been propagated, and if relevant AFTER the SignalListener.doAfterComplete()
or SignalListener.doAfterError(Throwable)
events. If any doOnXxx handler throws, this handler is NOT invoked (see SignalListener.handleListenerError(Throwable)
instead).doFinally
in interface SignalListener<T>
Throwable
SignalListener.handleListenerError(Throwable)
public void doOnSubscription() throws Throwable
SignalListener
Publisher
acknowledged Subscription
.
The Subscription
is intentionally not exposed in order to avoid manipulation by the observer.
While SignalListener.doFirst()
is invoked right as the downstream Subscriber
is registered,
this method is invoked as the upstream answers back with a Subscription
(and before that
same Subscription
is passed downstream).
doOnSubscription
in interface SignalListener<T>
Throwable
SignalListener.doFirst()
public void doOnFusion(int negotiatedFusion) throws Throwable
SignalListener
Fuseable
operators. As the downstream operator
requests fusion, the upstream answers back with the compatible level of fusion it can handle. This negotiatedFusion
code is passed to this handler right before it is propagated downstream.doOnFusion
in interface SignalListener<T>
negotiatedFusion
- the final fusion mode negotiated by the upstream operator in response to a fusion request
from downstreamThrowable
protected int getFusionMode()
Fuseable.SYNC
and Fuseable.ASYNC
) as relevant
if some fusion was negotiated. Fuseable.NONE
if fusion was never requested, or if it couldn't be negotiated.public void doOnRequest(long requested) throws Throwable
SignalListener
This is invoked before the request is propagated upstream.
doOnRequest
in interface SignalListener<T>
requested
- the downstream demandThrowable
public void doOnCancel() throws Throwable
SignalListener
Subscription
.
This handler is invoked before propagating the cancellation upstream, while SignalListener.doFinally(SignalType)
is invoked right after the cancellation has been propagated upstream.
doOnCancel
in interface SignalListener<T>
Throwable
SignalListener.doFinally(SignalType)
public void doOnNext(T value) throws Throwable
SignalListener
This handler is invoked before propagating the value downstream.
doOnNext
in interface SignalListener<T>
value
- the emitted valueThrowable
public void doOnComplete() throws Throwable
SignalListener
This handler is invoked before propagating the completion downstream, while both
SignalListener.doAfterComplete()
and SignalListener.doFinally(SignalType)
are invoked after.
doOnComplete
in interface SignalListener<T>
Throwable
SignalListener.doAfterComplete()
,
SignalListener.doFinally(SignalType)
public void doOnError(Throwable error) throws Throwable
SignalListener
This handler is invoked before propagating the error downstream, while both
SignalListener.doAfterError(Throwable)
and SignalListener.doFinally(SignalType)
are invoked after.
doOnError
in interface SignalListener<T>
error
- the exception that terminated the sequenceThrowable
SignalListener.doAfterError(Throwable)
,
SignalListener.doFinally(SignalType)
public void doAfterComplete() throws Throwable
SignalListener
This handler is invoked after propagating the completion downstream, similar to SignalListener.doFinally(SignalType)
and unlike SignalListener.doOnComplete()
.
doAfterComplete
in interface SignalListener<T>
Throwable
public void doAfterError(Throwable error) throws Throwable
SignalListener
This handler is invoked after propagating the error downstream, similar to SignalListener.doFinally(SignalType)
and unlike SignalListener.doOnError(Throwable)
.
doAfterError
in interface SignalListener<T>
error
- the exception that terminated the sequenceThrowable
public void doOnMalformedOnNext(T value) throws Throwable
SignalListener
Subscriber.onNext(Object)
, which are onNext happening after the sequence has already terminated
via Subscriber.onComplete()
or Subscriber.onError(Throwable)
.
Note that after this handler is invoked, the value is automatically dropped
.
If this handler fails with an exception, that exception is dropped
before the
value is also dropped.
doOnMalformedOnNext
in interface SignalListener<T>
value
- the value for which an emission was attempted (which will be automatically dropped afterwards)Throwable
public void doOnMalformedOnComplete() throws Throwable
SignalListener
Subscriber.onComplete()
, which means the sequence has already terminated
via Subscriber.onComplete()
or Subscriber.onError(Throwable)
.
If this handler fails with an exception, that exception is dropped
.
doOnMalformedOnComplete
in interface SignalListener<T>
Throwable
public void doOnMalformedOnError(Throwable error) throws Throwable
SignalListener
Subscriber.onError(Throwable)
, which means the sequence has already terminated
via Subscriber.onComplete()
or Subscriber.onError(Throwable)
.
Note that after this handler is invoked, the exception is automatically dropped
.
If this handler fails with an exception, that exception is dropped
before the
original onError exception is also dropped.
doOnMalformedOnError
in interface SignalListener<T>
error
- the extraneous exception (which will be automatically dropped afterwards)Throwable
public void handleListenerError(Throwable listenerError)
SignalListener
SignalListener
handler fails, callers are expected to first invoke this method then to propagate
the listenerError
downstream 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
SignalListener.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 by SignalListener.doFinally(SignalType)
.
handleListenerError
in interface SignalListener<T>
listenerError
- the exception thrown from a SignalListener
handler method