Package graphql.execution.reactive
Class SingleSubscriberPublisher<T>
- java.lang.Object
-
- graphql.execution.reactive.SingleSubscriberPublisher<T>
-
- Type Parameters:
T
- the things to publish
- All Implemented Interfaces:
org.reactivestreams.Publisher<T>
public class SingleSubscriberPublisher<T> extends java.lang.Object implements org.reactivestreams.Publisher<T>
A Publisher of things that are buffered and handles a single subscriber at a time. Rule #1 of reactive streams is don't write your own implementation. However rule #1 of graphql-java is that we have no unnecessary dependencies and force users into a code corner. So we chose to have a very simple implementation (single subscriber) implementation that allows a stream of results to be streamed out. People can wrap this is a more complete implementation if they so choose. Inspired by Public Domain CC0 code at https://github.com/jroper/reactive-streams-servlet/tree/master/reactive-streams-servlet/src/main/java/org/reactivestreams/servlet
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
SingleSubscriberPublisher.OnSubscriptionCallback
This is called when a subscription is made to the publisherprivate class
SingleSubscriberPublisher.SimpleSubscription
-
Field Summary
Fields Modifier and Type Field Description private java.util.Deque<T>
dataQ
private long
demand
private NonBlockingMutexExecutor
mutex
private boolean
noMoreData
private java.lang.Throwable
pendingThrowable
private boolean
running
private org.reactivestreams.Subscriber<? super T>
subscriber
private SingleSubscriberPublisher.OnSubscriptionCallback
subscriptionCallback
-
Constructor Summary
Constructors Constructor Description SingleSubscriberPublisher()
Constructs a publisher with no callback when subscribedSingleSubscriberPublisher(SingleSubscriberPublisher.OnSubscriptionCallback subscriptionCallback)
The producing code can provide a callback to know when the subscriber attaches
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
handleError(java.lang.Throwable t)
private void
handleOnComplete()
private void
maybeReadInMutex()
void
noMoreData()
Called by the producing code to say there is no more data to offer and the stream is completevoid
offer(T data)
Called from the producing code to offer data up ready for a subscriber to read itvoid
offerError(java.lang.Throwable t)
void
subscribe(org.reactivestreams.Subscriber<? super T> subscriber)
-
-
-
Field Detail
-
dataQ
private final java.util.Deque<T> dataQ
-
mutex
private final NonBlockingMutexExecutor mutex
-
subscriptionCallback
private final SingleSubscriberPublisher.OnSubscriptionCallback subscriptionCallback
-
subscriber
private org.reactivestreams.Subscriber<? super T> subscriber
-
pendingThrowable
private java.lang.Throwable pendingThrowable
-
running
private boolean running
-
noMoreData
private boolean noMoreData
-
demand
private long demand
-
-
Constructor Detail
-
SingleSubscriberPublisher
public SingleSubscriberPublisher()
Constructs a publisher with no callback when subscribed
-
SingleSubscriberPublisher
public SingleSubscriberPublisher(SingleSubscriberPublisher.OnSubscriptionCallback subscriptionCallback)
The producing code can provide a callback to know when the subscriber attaches- Parameters:
subscriptionCallback
- the callback when some ones
-
-
Method Detail
-
offer
public void offer(T data)
Called from the producing code to offer data up ready for a subscriber to read it- Parameters:
data
- the data to offer
-
noMoreData
public void noMoreData()
Called by the producing code to say there is no more data to offer and the stream is complete
-
offerError
public void offerError(java.lang.Throwable t)
-
handleError
private void handleError(java.lang.Throwable t)
-
handleOnComplete
private void handleOnComplete()
-
subscribe
public void subscribe(org.reactivestreams.Subscriber<? super T> subscriber)
- Specified by:
subscribe
in interfaceorg.reactivestreams.Publisher<T>
-
maybeReadInMutex
private void maybeReadInMutex()
-
-