Class BaseSubscriber<T>
- All Implemented Interfaces:
Subscriber<T>,Subscription,CoreSubscriber<T>,Disposable
Subscriber implementation that lets the user
perform a request(long) and cancel() on it directly. As the targeted
use case is to manually handle requests, the hookOnSubscribe(Subscription) and
hookOnNext(Object) hooks are expected to be implemented, but they nonetheless
default to an unbounded request at subscription time. If you need to define a Context
for this BaseSubscriber, simply override its CoreSubscriber.currentContext() method.
Override the other optional hooks hookOnComplete(),
hookOnError(Throwable) and hookOnCancel()
to customize the base behavior. You also have a termination hook,
hookFinally(SignalType).
Most of the time, exceptions triggered inside hooks are propagated to
onError(Throwable) (unless there is a fatal exception). The class is in the
reactor.core.publisher package, as this subscriber is tied to a single
Publisher.
- Author:
- Simon Baslé
-
Nested Class Summary
Nested classes/interfaces inherited from interface reactor.core.Disposable
Disposable.Composite, Disposable.Swap -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidcancel()voiddispose()protected voidhookFinally(SignalType type) Optional hook executed after any of the termination events (onError, onComplete, cancel).protected voidOptional hook executed when the subscription is cancelled by calling this Subscriber'scancel()method.protected voidOptional hook for completion processing.protected voidhookOnError(Throwable throwable) Optional hook for error processing.protected voidhookOnNext(T value) Hook for processing of onNext values.protected voidhookOnSubscribe(Subscription subscription) Hook for further processing of onSubscribe's Subscription.booleanOptionally return true when the resource or task is disposed.final voidfinal voidfinal voidfinal voidImplementors should initialize any state used bySubscriber.onNext(Object)before callingSubscription.request(long).final voidrequest(long n) final voidRequestan unbounded amount.toString()protected Subscriptionupstream()Return currentSubscriptionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface reactor.core.CoreSubscriber
currentContext
-
Constructor Details
-
BaseSubscriber
public BaseSubscriber()
-
-
Method Details
-
upstream
Return currentSubscription- Returns:
- current
Subscription
-
isDisposed
public boolean isDisposed()Description copied from interface:DisposableOptionally return true when the resource or task is disposed.Implementations are not required to track disposition and as such may never return true even when disposed. However, they MUST only return true when there's a guarantee the resource or task is disposed.
- Specified by:
isDisposedin interfaceDisposable- Returns:
- true when there's a guarantee the resource or task is disposed.
-
dispose
public void dispose()- Specified by:
disposein interfaceDisposable
-
hookOnSubscribe
Hook for further processing of onSubscribe's Subscription. Implement this method to callrequest(long)as an initial request. Values other than the unboundedLong.MAX_VALUEimply that you'll also call request inhookOnNext(Object).Defaults to request unbounded Long.MAX_VALUE as in
requestUnbounded()- Parameters:
subscription- the subscription to optionally process
-
hookOnNext
Hook for processing of onNext values. You can callrequest(long)here to further request data from the sourcePublisherif theinitial requestwasn't unbounded.Defaults to doing nothing.
- Parameters:
value- the emitted value to process
-
hookOnComplete
protected void hookOnComplete()Optional hook for completion processing. Defaults to doing nothing. -
hookOnError
Optional hook for error processing. Default is to callExceptions.errorCallbackNotImplemented(Throwable).- Parameters:
throwable- the error to process
-
hookOnCancel
protected void hookOnCancel()Optional hook executed when the subscription is cancelled by calling this Subscriber'scancel()method. Defaults to doing nothing. -
hookFinally
Optional hook executed after any of the termination events (onError, onComplete, cancel). The hook is executed in addition to and afterhookOnError(Throwable),hookOnComplete()andhookOnCancel()hooks, even if these callbacks fail. Defaults to doing nothing. A failure of the callback will be caught byOperators.onErrorDropped(Throwable, reactor.util.context.Context).- Parameters:
type- the type of termination event that triggered the hook (SignalType.ON_ERROR,SignalType.ON_COMPLETEorSignalType.CANCEL)
-
onSubscribe
Description copied from interface:CoreSubscriberImplementors should initialize any state used bySubscriber.onNext(Object)before callingSubscription.request(long). Should furtheronNextrelated state modification occur, thread-safety will be required.Note that an invalid request
<= 0will not produce an onError and will simply be ignored or reported through a debug-enabledLogger.- Specified by:
onSubscribein interfaceCoreSubscriber<T>- Specified by:
onSubscribein interfaceSubscriber<T>
-
onNext
- Specified by:
onNextin interfaceSubscriber<T>
-
onError
- Specified by:
onErrorin interfaceSubscriber<T>
-
onComplete
public final void onComplete()- Specified by:
onCompletein interfaceSubscriber<T>
-
request
public final void request(long n) - Specified by:
requestin interfaceSubscription
-
requestUnbounded
public final void requestUnbounded()Requestan unbounded amount. -
cancel
public final void cancel()- Specified by:
cancelin interfaceSubscription
-
toString
-