Class BaseSubscriberAdapter<T,U>
- java.lang.Object
-
- software.amazon.awssdk.utils.async.DelegatingSubscriber<T,U>
-
- software.amazon.awssdk.utils.async.BaseSubscriberAdapter<T,U>
-
- Type Parameters:
T- the type that the delegate subscriber demands.U- the type sent by the publisher this subscriber is subscribed to.
- All Implemented Interfaces:
org.reactivestreams.Subscriber<T>
- Direct Known Subclasses:
DelegatingBufferingSubscriber,FlatteningSubscriber
@SdkProtectedApi public abstract class BaseSubscriberAdapter<T,U> extends DelegatingSubscriber<T,U>
Base of subscribers that can adapt one type to another. This subscriber will receive onNext signal with theUtype, but will need tofulfill the downstream demandof the delegate subscriber with instance of theTtype.
-
-
Field Summary
Fields Modifier and Type Field Description protected AtomicLongdownstreamDemandThe amount of unfulfilled demand the downstream subscriber has opened against us.protected AtomicBooleanhandlingStateUpdateA flag that is used to ensure that only one thread is handling updates to the state of this subscriber at a time.protected booleanonCompleteCalledByUpstreamWhether the upstream subscriber has called onComplete on us.protected AtomicReference<Throwable>onErrorFromUpstreamWhether the upstream subscriber has called onError on us.protected booleanterminalCallMadeDownstreamWhether we have called onComplete or onNext on the downstream subscriber.protected AtomicLongupstreamDemandThe amount of unfulfilled demand open against the upstream subscriber.protected org.reactivestreams.SubscriptionupstreamSubscriptionThe subscription to the upstream subscriber.-
Fields inherited from class software.amazon.awssdk.utils.async.DelegatingSubscriber
subscriber
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBaseSubscriberAdapter(org.reactivestreams.Subscriber<? super U> subscriber)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract voidfulfillDownstreamDemand()This method is called when demand from the downstream subscriber needs to be fulfilled.protected voidhandleStateUpdate()This is invoked after each downstream request or upstream onNext, onError or onComplete.voidonComplete()voidonError(Throwable throwable)voidonNext(T item)voidonSubscribe(org.reactivestreams.Subscription subscription)
-
-
-
Field Detail
-
upstreamDemand
protected final AtomicLong upstreamDemand
The amount of unfulfilled demand open against the upstream subscriber.
-
downstreamDemand
protected final AtomicLong downstreamDemand
The amount of unfulfilled demand the downstream subscriber has opened against us.
-
handlingStateUpdate
protected final AtomicBoolean handlingStateUpdate
A flag that is used to ensure that only one thread is handling updates to the state of this subscriber at a time. This allows us to ensure that the downstream onNext, onComplete and onError are only ever invoked serially.
-
onErrorFromUpstream
protected final AtomicReference<Throwable> onErrorFromUpstream
Whether the upstream subscriber has called onError on us. If this is null, we haven't gotten an onError. If it's non-null this will be the exception that the upstream passed to our onError. After we get an onError, we'll call onError on the downstream subscriber as soon as possible.
-
terminalCallMadeDownstream
protected volatile boolean terminalCallMadeDownstream
Whether we have called onComplete or onNext on the downstream subscriber.
-
onCompleteCalledByUpstream
protected volatile boolean onCompleteCalledByUpstream
Whether the upstream subscriber has called onComplete on us. After this happens, we'll drain any outstanding items in the allItems queue and then call onComplete on the downstream subscriber.
-
upstreamSubscription
protected org.reactivestreams.Subscription upstreamSubscription
The subscription to the upstream subscriber.
-
-
Constructor Detail
-
BaseSubscriberAdapter
protected BaseSubscriberAdapter(org.reactivestreams.Subscriber<? super U> subscriber)
-
-
Method Detail
-
fulfillDownstreamDemand
protected abstract void fulfillDownstreamDemand()
This method is called when demand from the downstream subscriber needs to be fulfilled. Called in a loop untildownstreamDemandis no longer needed. Implementations are responsible for decrementing thedownstreamDemandaccordingly as demand gets fulfilled.
-
onSubscribe
public void onSubscribe(org.reactivestreams.Subscription subscription)
- Specified by:
onSubscribein interfaceorg.reactivestreams.Subscriber<T>- Overrides:
onSubscribein classDelegatingSubscriber<T,U>
-
onNext
public void onNext(T item)
-
onError
public void onError(Throwable throwable)
- Specified by:
onErrorin interfaceorg.reactivestreams.Subscriber<T>- Overrides:
onErrorin classDelegatingSubscriber<T,U>
-
onComplete
public void onComplete()
- Specified by:
onCompletein interfaceorg.reactivestreams.Subscriber<T>- Overrides:
onCompletein classDelegatingSubscriber<T,U>
-
handleStateUpdate
protected void handleStateUpdate()
This is invoked after each downstream request or upstream onNext, onError or onComplete.
-
-