Package graphql.execution.reactive
Class CompletionStageSubscriber<U,D>
- java.lang.Object
-
- graphql.execution.reactive.CompletionStageSubscriber<U,D>
-
- Type Parameters:
U- published upstream elementsD- mapped downstream values
- All Implemented Interfaces:
org.reactivestreams.Subscriber<U>
- Direct Known Subclasses:
CompletionStageOrderedSubscriber
public class CompletionStageSubscriber<U,D> extends java.lang.Object implements org.reactivestreams.Subscriber<U>This subscriber can be used to map between aPublisherof U elements and map them intoCompletionStageof D promises.
-
-
Field Summary
Fields Modifier and Type Field Description protected org.reactivestreams.SubscriptiondelegatingSubscriptionprotected org.reactivestreams.Subscriber<? super D>downstreamSubscriberprotected java.util.Queue<java.util.concurrent.CompletionStage<?>>inFlightDataQprotected java.util.concurrent.atomic.AtomicBooleanisTerminalprotected LockKit.ReentrantLocklockprotected java.util.function.Function<U,java.util.concurrent.CompletionStage<D>>mapperprotected java.util.concurrent.atomic.AtomicReference<java.lang.Runnable>onCompleteRun
-
Constructor Summary
Constructors Constructor Description CompletionStageSubscriber(java.util.function.Function<U,java.util.concurrent.CompletionStage<D>> mapper, org.reactivestreams.Subscriber<? super D> downstreamSubscriber)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidfinallyAfterEachPromiseFinishes(boolean isInFlightEmpty)org.reactivestreams.Subscriber<? super D>getDownstreamSubscriber()Get instance of downstream subscriberprotected voidhandleThrowableDuringMapping(java.lang.Throwable throwable)protected booleaninFlightQIsEmpty()protected booleanisTerminal()The two terminal states are onComplete or onErrorprotected voidofferToInFlightQ(java.util.concurrent.CompletionStage<?> completionStage)voidonComplete()voidonError(java.lang.Throwable t)voidonNext(U u)voidonSubscribe(org.reactivestreams.Subscription subscription)protected voidwhenNextFinished(java.util.concurrent.CompletionStage<D> completionStage, D d, java.lang.Throwable throwable)This is called as each mappedCompletionStagecompletes with a value or exception
-
-
-
Field Detail
-
mapper
protected final java.util.function.Function<U,java.util.concurrent.CompletionStage<D>> mapper
-
downstreamSubscriber
protected final org.reactivestreams.Subscriber<? super D> downstreamSubscriber
-
delegatingSubscription
protected org.reactivestreams.Subscription delegatingSubscription
-
inFlightDataQ
protected final java.util.Queue<java.util.concurrent.CompletionStage<?>> inFlightDataQ
-
lock
protected final LockKit.ReentrantLock lock
-
onCompleteRun
protected final java.util.concurrent.atomic.AtomicReference<java.lang.Runnable> onCompleteRun
-
isTerminal
protected final java.util.concurrent.atomic.AtomicBoolean isTerminal
-
-
Method Detail
-
getDownstreamSubscriber
public org.reactivestreams.Subscriber<? super D> getDownstreamSubscriber()
Get instance of downstream subscriber- Returns:
Subscriber
-
onSubscribe
public void onSubscribe(org.reactivestreams.Subscription subscription)
- Specified by:
onSubscribein interfaceorg.reactivestreams.Subscriber<U>
-
whenNextFinished
protected void whenNextFinished(java.util.concurrent.CompletionStage<D> completionStage, D d, java.lang.Throwable throwable)
This is called as each mappedCompletionStagecompletes with a value or exception- Parameters:
completionStage- the completion stage that has completedd- the value completedthrowable- or the throwable that happened during completion
-
finallyAfterEachPromiseFinishes
protected void finallyAfterEachPromiseFinishes(boolean isInFlightEmpty)
-
handleThrowableDuringMapping
protected void handleThrowableDuringMapping(java.lang.Throwable throwable)
-
onError
public void onError(java.lang.Throwable t)
- Specified by:
onErrorin interfaceorg.reactivestreams.Subscriber<U>
-
onComplete
public void onComplete()
- Specified by:
onCompletein interfaceorg.reactivestreams.Subscriber<U>
-
offerToInFlightQ
protected void offerToInFlightQ(java.util.concurrent.CompletionStage<?> completionStage)
-
inFlightQIsEmpty
protected boolean inFlightQIsEmpty()
-
isTerminal
protected boolean isTerminal()
The two terminal states are onComplete or onError- Returns:
- true if it's in a terminal state
-
-