Skip to content

Commit 893eb70

Browse files
authored
stub: Clarify flow control javadoc (grpc#12977)
Remove vestigial references to credit-based flow control and the suggestion that a request() for messages directly corresponds to the number of messages a peer could subsequently send before its end of the stream went !isReady(). In fact, okhttp, netty and binder transports all buffer messages meaning the outbound stream can be isReady() even when the receiver has no outstanding request()s for messages. Furthermore, those buffers are sized in bytes and not all messages are the same size. So consuming an inbound's next message may not cause a non-ready outbound to become ready again. Replace this with a short discussion of what is actually guaranteed by every transport.
1 parent 1af3b03 commit 893eb70

3 files changed

Lines changed: 16 additions & 10 deletions

File tree

‎stub/src/main/java/io/grpc/stub/CallStreamObserver.java‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@
4747
* <p>Like {@code StreamObserver}, implementations are not required to be thread-safe; if multiple
4848
* threads will be writing to an instance concurrently, the application must synchronize its calls.
4949
*
50+
* <p>On flow control: {@link #isReady} returns whether an observer can accept more messages without
51+
* excessive buffering. Readiness is affected by the volume of messages previously sent and how much
52+
* of that data has been requested by the peer application. But this effect may not be immediate and
53+
* may not be message-for-message. All that's guaranteed is this: if an outbound is being fed
54+
* messages but the peer is not requesting them, the outbound's {@link #isReady} will eventually
55+
* return false. If, later, the peer does ask for enough of those messages, the outbound observer
56+
* will eventually become ready again.
57+
*
5058
* <p>DO NOT MOCK: The API is too complex to reliably mock. Use InProcessChannelBuilder to create
5159
* "real" RPCs suitable for testing.
5260
*
@@ -87,9 +95,10 @@ public abstract class CallStreamObserver<V> implements StreamObserver<V> {
8795
public abstract void setOnReadyHandler(Runnable onReadyHandler);
8896

8997
/**
90-
* Disables automatic flow control where a token is returned to the peer after a call
91-
* to the 'inbound' {@link io.grpc.stub.StreamObserver#onNext(Object)} has completed. If disabled
92-
* an application must make explicit calls to {@link #request} to receive messages.
98+
* Disables automatic flow control, a mode where another message is implicitly {@link #request}ed
99+
* after each call to the inbound's {@link StreamObserver#onNext(Object)} returns.
100+
*
101+
* <p>If disabled an application must make explicit calls to {@link #request} to receive messages.
93102
*
94103
* <p>On client-side this method may only be called during {@link
95104
* ClientResponseObserver#beforeStart}. On server-side it may only be called during the initial
@@ -108,16 +117,15 @@ public abstract class CallStreamObserver<V> implements StreamObserver<V> {
108117
* </li>
109118
* </ul>
110119
* </p>
111-
*
120+
*
112121
* <p>This API is being replaced, but is not yet deprecated. On server-side it being replaced
113122
* with {@link ServerCallStreamObserver#disableAutoRequest}. On client-side {@link
114123
* ClientCallStreamObserver#disableAutoRequestWithInitial disableAutoRequestWithInitial(1)}.
115124
*/
116125
public abstract void disableAutoInboundFlowControl();
117126

118127
/**
119-
* Requests the peer to produce {@code count} more messages to be delivered to the 'inbound'
120-
* {@link StreamObserver}.
128+
* Requests that {@code count} more messages be delivered to the 'inbound' {@link StreamObserver}.
121129
*
122130
* <p>This method is safe to call from multiple threads without external synchronization.
123131
*

‎stub/src/main/java/io/grpc/stub/ClientCallStreamObserver.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ public void disableAutoRequestWithInitial(int request) {
9292
public abstract void setOnReadyHandler(Runnable onReadyHandler);
9393

9494
/**
95-
* Requests the peer to produce {@code count} more messages to be delivered to the 'inbound'
96-
* {@link StreamObserver}.
95+
* Requests that {@code count} more messages be delivered to the 'inbound' {@link StreamObserver}.
9796
*
9897
* <p>This method is safe to call from multiple threads without external synchronization.
9998
*

‎stub/src/main/java/io/grpc/stub/ServerCallStreamObserver.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ public void disableAutoRequest() {
147147
public abstract void setOnReadyHandler(Runnable onReadyHandler);
148148

149149
/**
150-
* Requests the peer to produce {@code count} more messages to be delivered to the 'inbound'
151-
* {@link StreamObserver}.
150+
* Requests that {@code count} more messages be delivered to the 'inbound' {@link StreamObserver}.
152151
*
153152
* <p>This method is safe to call from multiple threads without external synchronization.
154153
*

0 commit comments

Comments
 (0)