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 aPublisher
of U elements and map them intoCompletionStage
of D promises.
-
-
Field Summary
Fields Modifier and Type Field Description protected org.reactivestreams.Subscription
delegatingSubscription
protected org.reactivestreams.Subscriber<? super D>
downstreamSubscriber
protected java.util.Queue<java.util.concurrent.CompletionStage<?>>
inFlightDataQ
protected java.util.concurrent.atomic.AtomicBoolean
isTerminal
protected LockKit.ReentrantLock
lock
protected java.util.function.Function<U,java.util.concurrent.CompletionStage<D>>
mapper
protected 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 void
finallyAfterEachPromiseFinishes(boolean isInFlightEmpty)
org.reactivestreams.Subscriber<? super D>
getDownstreamSubscriber()
Get instance of downstream subscriberprotected void
handleThrowableDuringMapping(java.lang.Throwable throwable)
protected boolean
inFlightQIsEmpty()
protected boolean
isTerminal()
The two terminal states are onComplete or onErrorprotected void
offerToInFlightQ(java.util.concurrent.CompletionStage<?> completionStage)
void
onComplete()
void
onError(java.lang.Throwable t)
void
onNext(U u)
void
onSubscribe(org.reactivestreams.Subscription subscription)
protected void
whenNextFinished(java.util.concurrent.CompletionStage<D> completionStage, D d, java.lang.Throwable throwable)
This is called as each mappedCompletionStage
completes 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:
onSubscribe
in 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 mappedCompletionStage
completes 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:
onError
in interfaceorg.reactivestreams.Subscriber<U>
-
onComplete
public void onComplete()
- Specified by:
onComplete
in 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
-
-