T - Tpublic abstract class AbstractStreamObserverAndPublisher<T> extends AbstractUnimplementedQueue<T> implements org.reactivestreams.Publisher<T>, io.grpc.stub.StreamObserver<T>, org.reactivestreams.Subscription, Queue<T>
AbstractStreamObserverAndPublisher bridges the manual flow control idioms of
gRPC and Reactive Streams. This class takes messages off of a CallStreamObserver
and feeds them into a Publisher while respecting backpressure.
In order to keep backpressure working at the async boundary between
CallStreamObserver as an upstream, the AbstractSubscriberAndProducer
enable manual flow-control by calling
CallStreamObserver.disableAutoInboundFlowControl() at subscription time and
prefetch specified by prefetch number of
elements at first and then keeps the number of requested element on the same level
once the upstream sent amount of elements reach the specified
limit.
In addition, AbstractStreamObserverAndPublisher take an additional care for
some exotic cases when upstream does not respect backpressure of the
Reactive-Streams Subscriber as the downstream, so
AbstractStreamObserverAndPublisher employees Queue that enqueue each
incoming elements and in that way keeps excess of items. In turn, to avoid
Queue overwhelming, it is recommended to uses Queue with a fixed
size so in the case Queue.offer(Object) returns false the sender thread will
be blocked with a busy spin using LockSupport.parkNanos(long) try to enqueue
element into Queue until downstream deque element from it.| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_CHUNK_SIZE |
protected boolean |
outputFused |
protected io.grpc.stub.CallStreamObserver<?> |
subscription |
static int |
TWO_THIRDS_OF_DEFAULT_CHUNK_SIZE |
| Modifier and Type | Method and Description |
|---|---|
void |
cancel() |
void |
clear() |
protected void |
doOnCancel() |
boolean |
isCancelled() |
boolean |
isEmpty() |
void |
onCompleted() |
void |
onError(Throwable t) |
void |
onNext(T t) |
protected void |
onSubscribe(io.grpc.stub.CallStreamObserver<?> upstream) |
T |
poll() |
void |
request(long n) |
int |
size() |
void |
subscribe(org.reactivestreams.Subscriber<? super T> actual) |
add, addAll, contains, containsAll, element, iterator, offer, offer, peek, remove, remove, removeAll, retainAll, toArray, toArrayclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddAll, contains, containsAll, equals, hashCode, iterator, parallelStream, remove, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArraypublic static final int DEFAULT_CHUNK_SIZE
public static final int TWO_THIRDS_OF_DEFAULT_CHUNK_SIZE
protected volatile boolean outputFused
protected volatile io.grpc.stub.CallStreamObserver<?> subscription
protected void onSubscribe(io.grpc.stub.CallStreamObserver<?> upstream)
public void onError(Throwable t)
onError in interface io.grpc.stub.StreamObserver<T>public void onCompleted()
onCompleted in interface io.grpc.stub.StreamObserver<T>public void subscribe(org.reactivestreams.Subscriber<? super T> actual)
subscribe in interface org.reactivestreams.Publisher<T>public boolean isCancelled()
public void request(long n)
request in interface org.reactivestreams.Subscriptionpublic void cancel()
cancel in interface org.reactivestreams.Subscriptionprotected void doOnCancel()
public T poll()
public int size()
size in interface Collection<T>size in class AbstractUnimplementedQueue<T>public boolean isEmpty()
isEmpty in interface Collection<T>public void clear()
clear in interface Collection<T>Copyright © 2021. All rights reserved.