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
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 theU
type, but will need tofulfill the downstream demand
of the delegate subscriber with instance of theT
type.
-
-
Field Summary
Fields Modifier and Type Field Description protected AtomicLong
downstreamDemand
The amount of unfulfilled demand the downstream subscriber has opened against us.protected 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.protected boolean
onCompleteCalledByUpstream
Whether the upstream subscriber has called onComplete on us.protected AtomicReference<Throwable>
onErrorFromUpstream
Whether the upstream subscriber has called onError on us.protected boolean
terminalCallMadeDownstream
Whether we have called onComplete or onNext on the downstream subscriber.protected AtomicLong
upstreamDemand
The amount of unfulfilled demand open against the upstream subscriber.protected org.reactivestreams.Subscription
upstreamSubscription
The subscription to the upstream subscriber.-
Fields inherited from class software.amazon.awssdk.utils.async.DelegatingSubscriber
subscriber
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
BaseSubscriberAdapter(org.reactivestreams.Subscriber<? super U> subscriber)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
fulfillDownstreamDemand()
This method is called when demand from the downstream subscriber needs to be fulfilled.protected void
handleStateUpdate()
This is invoked after each downstream request or upstream onNext, onError or onComplete.void
onComplete()
void
onError(Throwable throwable)
void
onNext(T item)
void
onSubscribe(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 untildownstreamDemand
is no longer needed. Implementations are responsible for decrementing thedownstreamDemand
accordingly as demand gets fulfilled.
-
onSubscribe
public void onSubscribe(org.reactivestreams.Subscription subscription)
- Specified by:
onSubscribe
in interfaceorg.reactivestreams.Subscriber<T>
- Overrides:
onSubscribe
in classDelegatingSubscriber<T,U>
-
onNext
public void onNext(T item)
-
onError
public void onError(Throwable throwable)
- Specified by:
onError
in interfaceorg.reactivestreams.Subscriber<T>
- Overrides:
onError
in classDelegatingSubscriber<T,U>
-
onComplete
public void onComplete()
- Specified by:
onComplete
in interfaceorg.reactivestreams.Subscriber<T>
- Overrides:
onComplete
in classDelegatingSubscriber<T,U>
-
handleStateUpdate
protected void handleStateUpdate()
This is invoked after each downstream request or upstream onNext, onError or onComplete.
-
-