T - Tpublic abstract class AbstractSubscriberAndProducer<T> extends Object implements org.reactivestreams.Subscriber<T>, Runnable
Publisher and feeds them into a CallStreamObserver
while respecting backpressure. This class is the inverse of AbstractStreamObserverAndPublisher.
When a gRPC publisher's transport wants more data to transmit, the CallStreamObserver's onReady handler is
signaled. This handler must keep transmitting messages until CallStreamObserver.isReady() ceases to be true.
When a Publisher is subscribed to by a Subscriber, the
Publisher hands the Subscriber a Subscription. When the Subscriber
wants more messages from the Publisher, the Subscriber calls Subscription.request(long).
To bridge the two idioms: when gRPC wants more messages, the onReadyHandler is called and run()
calls the Subscription's request() method, asking the Publisher to produce another message.
Since this class is also registered as the Publisher's Subscriber, the onNext(Object)
method is called. onNext() passes the message to gRPC's StreamObserver.onNext(Object) method,
and then calls request() again if CallStreamObserver.isReady() is true. The loop of
request→pass→check is repeated until isReady() returns false, indicating that the outbound transmit buffer
is full and that backpressure must be applied.
| Modifier and Type | Field and Description |
|---|---|
protected io.grpc.stub.CallStreamObserver<T> |
downstream |
| Constructor and Description |
|---|
AbstractSubscriberAndProducer() |
| Modifier and Type | Method and Description |
|---|---|
void |
cancel() |
protected abstract org.reactivestreams.Subscription |
fuse(org.reactivestreams.Subscription subscription) |
boolean |
isCanceled() |
void |
onComplete() |
void |
onError(Throwable t) |
void |
onNext(T t) |
void |
onSubscribe(org.reactivestreams.Subscription subscription) |
protected Throwable |
prepareError(Throwable throwable) |
void |
run() |
void |
subscribe(io.grpc.stub.CallStreamObserver<T> downstream) |
protected volatile io.grpc.stub.CallStreamObserver<T> downstream
public void subscribe(io.grpc.stub.CallStreamObserver<T> downstream)
public void cancel()
public boolean isCanceled()
public void onSubscribe(org.reactivestreams.Subscription subscription)
onSubscribe in interface org.reactivestreams.Subscriber<T>public void onError(Throwable t)
onError in interface org.reactivestreams.Subscriber<T>public void onComplete()
onComplete in interface org.reactivestreams.Subscriber<T>protected abstract org.reactivestreams.Subscription fuse(org.reactivestreams.Subscription subscription)
Copyright © 2023. All rights reserved.