Skip to content

Commit 00dd36f

Browse files
committed
Redo javadoc changes after accepting the copy from master, and also add the javadoc for the "blockingV2" calls.
1 parent 3edd086 commit 00dd36f

1 file changed

Lines changed: 98 additions & 2 deletions

File tree

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

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ private ClientCalls() {}
7777
*
7878
* <p>If the provided {@code responseObserver} is an instance of {@link ClientResponseObserver},
7979
* {@code beforeStart()} will be called.
80+
*
81+
* <h3>Server errors</h3>
82+
* If the server completes the RPC with status code OK, then {@code
83+
* responseObserver.onCompleted()} is called at the end of the RPC. Otherwise the status and
84+
* trailers are passed as a Throwable to {@code onError()} and can be accessed with {@link
85+
* Status#fromThrowable} and {@link Status#trailersFromThrowable}.
8086
*/
8187
public static <ReqT, RespT> void asyncUnaryCall(
8288
ClientCall<ReqT, RespT> call, ReqT req, StreamObserver<RespT> responseObserver) {
@@ -91,6 +97,12 @@ public static <ReqT, RespT> void asyncUnaryCall(
9197
*
9298
* <p>If the provided {@code responseObserver} is an instance of {@link ClientResponseObserver},
9399
* {@code beforeStart()} will be called.
100+
*
101+
* <h3>Server errors</h3>
102+
* If the server completes the RPC with status code OK, then {@code
103+
* responseObserver.onCompleted()} is called at the end of the RPC. Otherwise the status and
104+
* trailers are passed as a Throwable to {@code onError()} and can be accessed with {@link
105+
* Status#fromThrowable} and {@link Status#trailersFromThrowable}.
94106
*/
95107
public static <ReqT, RespT> void asyncServerStreamingCall(
96108
ClientCall<ReqT, RespT> call, ReqT req, StreamObserver<RespT> responseObserver) {
@@ -106,6 +118,25 @@ public static <ReqT, RespT> void asyncServerStreamingCall(
106118
* <p>If the provided {@code responseObserver} is an instance of {@link ClientResponseObserver},
107119
* {@code beforeStart()} will be called.
108120
*
121+
* <h3>Client errors</h3>
122+
* {@link StreamObserver#onError} called on the request stream observer will result in stream
123+
* cancellation. The response
124+
* {@link StreamObserver} will be immediately notified of the cancellation with a
125+
* {@link io.grpc.StatusRuntimeException} with the exception passed to onError set as the cause
126+
* and the stream is considered closed. The server's request stream observer will receive an
127+
* {@link StreamObserver#onError} callback with a throwable which when converted to a status
128+
* with
129+
* Status.fromThrowable(), always has the status code CANCELLED and exception cause set to
130+
* null because the actual exception
131+
* passed by the client to onError is never actually transmitted to the server and the server
132+
* just receives a RST_STREAM frame indicating cancellation by the client.
133+
*
134+
* <h3>Server errors</h3>
135+
* If the server completes the RPC with status code OK, then {@code
136+
* responseObserver.onCompleted()} is called at the end of the RPC. Otherwise the status and
137+
* trailers are passed as a Throwable to {@code onError()} and can be accessed with {@link
138+
* Status#fromThrowable} and {@link Status#trailersFromThrowable}.
139+
*
109140
* @return request stream observer. It will extend {@link ClientCallStreamObserver}
110141
*/
111142
public static <ReqT, RespT> StreamObserver<ReqT> asyncClientStreamingCall(
@@ -122,6 +153,25 @@ public static <ReqT, RespT> StreamObserver<ReqT> asyncClientStreamingCall(
122153
* <p>If the provided {@code responseObserver} is an instance of {@link ClientResponseObserver},
123154
* {@code beforeStart()} will be called.
124155
*
156+
* <h3>Client errors</h3>
157+
* {@link StreamObserver#onError} called on the request stream observer will result in stream
158+
* cancellation. The response
159+
* {@link StreamObserver} will be immediately notified of the cancellation with a
160+
* {@link io.grpc.StatusRuntimeException} with the exception passed to onError set as the cause
161+
* and the stream is considered closed. The server's request stream observer will receive an
162+
* {@link StreamObserver#onError} callback with a throwable which when converted to a status
163+
* with
164+
* Status.fromThrowable(), always has the status code CANCELLED and exception cause set to
165+
* null because the actual exception
166+
* passed by the client to onError is never actually transmitted to the server and the server
167+
* just receives a RST_STREAM frame indicating cancellation by the client.
168+
*
169+
* <h3>Server errors</h3>
170+
* If the server completes the RPC with status code OK, then {@code
171+
* responseObserver.onCompleted()} is called at the end of the RPC. Otherwise the status and
172+
* trailers are passed as a Throwable to {@code onError()} and can be accessed with {@link
173+
* Status#fromThrowable} and {@link Status#trailersFromThrowable}.
174+
*
125175
* @return request stream observer. It will extend {@link ClientCallStreamObserver}
126176
*/
127177
public static <ReqT, RespT> StreamObserver<ReqT> asyncBidiStreamingCall(
@@ -134,6 +184,10 @@ public static <ReqT, RespT> StreamObserver<ReqT> asyncBidiStreamingCall(
134184
* Executes a unary call and blocks on the response. The {@code call} should not be already
135185
* started. After calling this method, {@code call} should no longer be used.
136186
*
187+
* <h3>Server errors</h3>
188+
* If the server completes the RPC with a non-OK status, a {@link StatusRuntimeException}
189+
* is thrown. The status code and trailers can be accessed from the exception.
190+
*
137191
* @return the single response message.
138192
* @throws StatusRuntimeException on error
139193
*/
@@ -149,6 +203,10 @@ public static <ReqT, RespT> RespT blockingUnaryCall(ClientCall<ReqT, RespT> call
149203
* Executes a unary call and blocks on the response. The {@code call} should not be already
150204
* started. After calling this method, {@code call} should no longer be used.
151205
*
206+
* <h3>Server errors</h3>
207+
* If the server completes the RPC with a non-OK status, a {@link StatusRuntimeException}
208+
* is thrown. The status code and trailers can be accessed from the exception.
209+
*
152210
* @return the single response message.
153211
* @throws StatusRuntimeException on error
154212
*/
@@ -186,6 +244,10 @@ public static <ReqT, RespT> RespT blockingUnaryCall(
186244
* Executes a unary call and blocks on the response,
187245
* throws a checked {@link StatusException}.
188246
*
247+
* <h3>Server errors</h3>
248+
* If the server completes the RPC with a non-OK status, a {@link StatusException}
249+
* is thrown. The status code and trailers can be accessed from the exception.
250+
*
189251
* @return the single response message.
190252
* @throws StatusException on error
191253
*/
@@ -204,7 +266,11 @@ public static <ReqT, RespT> RespT blockingV2UnaryCall(
204266
* response stream. The {@code call} should not be already started. After calling this method,
205267
* {@code call} should no longer be used.
206268
*
207-
* <p>The returned iterator may throw {@link StatusRuntimeException} on error.
269+
* <h3>Server errors</h3>
270+
* If the server completes the RPC with a non-OK status, the returned iterator will throw
271+
* a {@link StatusRuntimeException} when attempting to read the error response (e.g. in
272+
* {@link Iterator#hasNext} or {@link Iterator#next}). The status code and trailers can be
273+
* accessed from the exception.
208274
*
209275
* @return an iterator over the response stream.
210276
*/
@@ -219,7 +285,11 @@ public static <ReqT, RespT> Iterator<RespT> blockingServerStreamingCall(
219285
* Executes a server-streaming call returning a blocking {@link Iterator} over the
220286
* response stream.
221287
*
222-
* <p>The returned iterator may throw {@link StatusRuntimeException} on error.
288+
* <h3>Server errors</h3>
289+
* If the server completes the RPC with a non-OK status, the returned iterator will throw
290+
* a {@link StatusRuntimeException} when attempting to read the error response (e.g. in
291+
* {@link Iterator#hasNext} or {@link Iterator#next}). The status code and trailers can be
292+
* accessed from the exception.
223293
*
224294
* <p>Warning: the iterator can result in leaks if not completely consumed.
225295
*
@@ -242,6 +312,13 @@ public static <ReqT, RespT> Iterator<RespT> blockingServerStreamingCall(
242312
* <p>The methods {@link BlockingClientCall#hasNext()} and {@link
243313
* BlockingClientCall#cancel(String, Throwable)} can be used for more extensive control.
244314
*
315+
* <h3>Server errors</h3>
316+
* If the server completes the RPC with a non-OK status, the returned {@link BlockingClientCall}
317+
* will throw a {@link StatusException} when calling read or write operations (e.g.,
318+
* {@link BlockingClientCall#read()}, {@link BlockingClientCall#hasNext()}, or
319+
* {@link BlockingClientCall#write(Object)}). The status code and trailers can be accessed from
320+
* the exception.
321+
*
245322
* @return A {@link BlockingClientCall} that has had the request sent and halfClose called
246323
*/
247324
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/10918")
@@ -280,6 +357,13 @@ public static <ReqT, RespT> BlockingClientCall<ReqT, RespT> blockingV2ServerStre
280357
* {@link #blockingServerStreamingCall(Channel, MethodDescriptor, CallOptions, Object)}
281358
* which returns an iterator, which would leave the stream open if not completely consumed.
282359
*
360+
* <h3>Server errors</h3>
361+
* If the server completes the RPC with a non-OK status, the returned {@link BlockingClientCall}
362+
* will throw a {@link StatusException} when calling read or write operations (e.g.,
363+
* {@link BlockingClientCall#read()}, {@link BlockingClientCall#hasNext()}, or
364+
* {@link BlockingClientCall#write(Object)}). The status code and trailers can be accessed from
365+
* the exception.
366+
*
283367
* @return A {@link BlockingClientCall} which can be used by the client to write and receive
284368
* messages over the grpc channel.
285369
*/
@@ -294,6 +378,13 @@ public static <ReqT, RespT> BlockingClientCall<ReqT, RespT> blockingClientStream
294378
* ({@link BlockingClientCall}) which can be used by the client to send and receive messages over
295379
* the grpc channel.
296380
*
381+
* <h3>Server errors</h3>
382+
* If the server completes the RPC with a non-OK status, the returned {@link BlockingClientCall}
383+
* will throw a {@link StatusException} when calling read or write operations (e.g.,
384+
* {@link BlockingClientCall#read()}, {@link BlockingClientCall#hasNext()}, or
385+
* {@link BlockingClientCall#write(Object)}). The status code and trailers can be accessed from
386+
* the exception.
387+
*
297388
* @return an object representing the call which can be used to read, write and terminate it.
298389
*/
299390
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/10918")
@@ -316,6 +407,11 @@ public static <ReqT, RespT> BlockingClientCall<ReqT, RespT> blockingBidiStreamin
316407
* {@code call} should not be already started. After calling this method, {@code call} should no
317408
* longer be used.
318409
*
410+
* <h3>Server errors</h3>
411+
* If the server completes the RPC with a non-OK status, the returned future will fail with
412+
* a {@link StatusRuntimeException}. The status code and trailers can be accessed from the
413+
* exception.
414+
*
319415
* @return a future for the single response message.
320416
*/
321417
public static <ReqT, RespT> ListenableFuture<RespT> futureUnaryCall(

0 commit comments

Comments
 (0)