Skip to content

Commit f8b457a

Browse files
committed
Address review comments.
1 parent 916e848 commit f8b457a

2 files changed

Lines changed: 119 additions & 90 deletions

File tree

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

Lines changed: 55 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,10 @@ private ClientCalls() {}
7272
* {@code beforeStart()} will be called.
7373
*
7474
* <h3>Server errors</h3>
75-
* If the throwable sent to the server's outbound {@link StreamObserver}'s onError
76-
* is a {@link StatusException} or {@link StatusRuntimeException}, that status code will be
77-
* received by the {@link ClientCall}'s onClose, and UNKNOWN status code otherwise. Its
78-
* description will be encoded to the stream trailer, but the cause (which may contain server
79-
* application's information) will not.
75+
* If the server completes the RPC with status code OK, then {@code
76+
* responseObserver.onCompleted()} is called at the end of the RPC. Otherwise the status and
77+
* trailers are passed as a Throwable to {@code onError()} and can be accessed with {@link
78+
* Status#fromThrowable} and {@link Status#trailersFromThrowable}.
8079
*/
8180
public static <ReqT, RespT> void asyncUnaryCall(
8281
ClientCall<ReqT, RespT> call, ReqT req, StreamObserver<RespT> responseObserver) {
@@ -93,11 +92,10 @@ public static <ReqT, RespT> void asyncUnaryCall(
9392
* {@code beforeStart()} will be called.
9493
*
9594
* <h3>Server errors</h3>
96-
* If the throwable sent to the server's outbound {@link StreamObserver}'s onError
97-
* is a {@link StatusException} or {@link StatusRuntimeException}, that status code will be
98-
* received by the {@link ClientCall}'s onClose, and UNKNOWN status code otherwise. Its
99-
* description will be encoded to the stream trailer, but the cause (which may contain server
100-
* application's information) will not.
95+
* If the server completes the RPC with status code OK, then {@code
96+
* responseObserver.onCompleted()} is called at the end of the RPC. Otherwise the status and
97+
* trailers are passed as a Throwable to {@code onError()} and can be accessed with {@link
98+
* Status#fromThrowable} and {@link Status#trailersFromThrowable}.
10199
*/
102100
public static <ReqT, RespT> void asyncServerStreamingCall(
103101
ClientCall<ReqT, RespT> call, ReqT req, StreamObserver<RespT> responseObserver) {
@@ -113,24 +111,26 @@ public static <ReqT, RespT> void asyncServerStreamingCall(
113111
* <p>If the provided {@code responseObserver} is an instance of {@link ClientResponseObserver},
114112
* {@code beforeStart()} will be called.
115113
*
116-
* @return request stream observer. It will extend {@link ClientCallStreamObserver}
117-
*
118114
* <h3>Client errors</h3>
119-
* onError called on the request stream observer will result in stream cancellation. The response
115+
* {@link StreamObserver#onError} called on the request stream observer will result in stream
116+
* cancellation. The response
120117
* {@link StreamObserver} will be immediately notified of the cancellation with a
121118
* {@link io.grpc.StatusRuntimeException} with the exception passed to onError set as the cause
122119
* and the stream is considered closed. The server's request stream observer will receive an
123-
* onError callback with a {@link io.grpc.StatusRuntimeException} for the cancellation with the
124-
* message 'Client cancelled', and exception cause set to null because the actual exception
120+
* {@link StreamObserver#onError} callback with a throwable which when converted to a status
121+
* with
122+
* Status.fromThrowable(), always has the status code CANCELLED and exception cause set to
123+
* null because the actual exception
125124
* passed by the client to onError is never actually transmitted to the server and the server
126125
* just receives a RST_STREAM frame indicating cancellation by the client.
127126
*
128127
* <h3>Server errors</h3>
129-
* If the throwable sent to the server's outbound {@link StreamObserver}'s onError
130-
* is a {@link StatusException} or {@link StatusRuntimeException}, that status code will be
131-
* received by the {@link ClientCall}'s onClose, and UNKNOWN status code otherwise. Its
132-
* description will be encoded to the stream trailer, but the cause (which may contain server
133-
* application's information) will not.
128+
* If the server completes the RPC with status code OK, then {@code
129+
* responseObserver.onCompleted()} is called at the end of the RPC. Otherwise the status and
130+
* trailers are passed as a Throwable to {@code onError()} and can be accessed with {@link
131+
* Status#fromThrowable} and {@link Status#trailersFromThrowable}.
132+
*
133+
* @return request stream observer. It will extend {@link ClientCallStreamObserver}
134134
*/
135135
public static <ReqT, RespT> StreamObserver<ReqT> asyncClientStreamingCall(
136136
ClientCall<ReqT, RespT> call,
@@ -146,24 +146,26 @@ public static <ReqT, RespT> StreamObserver<ReqT> asyncClientStreamingCall(
146146
* <p>If the provided {@code responseObserver} is an instance of {@link ClientResponseObserver},
147147
* {@code beforeStart()} will be called.
148148
*
149-
* @return request stream observer. It will extend {@link ClientCallStreamObserver}
150-
*
151149
* <h3>Client errors</h3>
152-
* onError called on the request stream observer will result in stream cancellation. The response
150+
* {@link StreamObserver#onError} called on the request stream observer will result in stream
151+
* cancellation. The response
153152
* {@link StreamObserver} will be immediately notified of the cancellation with a
154153
* {@link io.grpc.StatusRuntimeException} with the exception passed to onError set as the cause
155154
* and the stream is considered closed. The server's request stream observer will receive an
156-
* onError callback with a {@link io.grpc.StatusRuntimeException} for the cancellation with the
157-
* message 'Client cancelled', and exception cause set to null because the actual exception
155+
* {@link StreamObserver#onError} callback with a throwable which when converted to a status
156+
* with
157+
* Status.fromThrowable(), always has the status code CANCELLED and exception cause set to
158+
* null because the actual exception
158159
* passed by the client to onError is never actually transmitted to the server and the server
159160
* just receives a RST_STREAM frame indicating cancellation by the client.
160161
*
161162
* <h3>Server errors</h3>
162-
* If the throwable sent to the server's outbound {@link StreamObserver}'s onError
163-
* is a {@link StatusException} or {@link StatusRuntimeException}, that status code will be
164-
* received by the {@link ClientCall}'s onClose, and UNKNOWN status code otherwise. Its
165-
* description will be encoded to the stream trailer, but the cause (which may contain server
166-
* application's information) will not.
163+
* If the server completes the RPC with status code OK, then {@code
164+
* responseObserver.onCompleted()} is called at the end of the RPC. Otherwise the status and
165+
* trailers are passed as a Throwable to {@code onError()} and can be accessed with {@link
166+
* Status#fromThrowable} and {@link Status#trailersFromThrowable}.
167+
*
168+
* @return request stream observer. It will extend {@link ClientCallStreamObserver}
167169
*/
168170
public static <ReqT, RespT> StreamObserver<ReqT> asyncBidiStreamingCall(
169171
ClientCall<ReqT, RespT> call, StreamObserver<RespT> responseObserver) {
@@ -175,6 +177,10 @@ public static <ReqT, RespT> StreamObserver<ReqT> asyncBidiStreamingCall(
175177
* Executes a unary call and blocks on the response. The {@code call} should not be already
176178
* started. After calling this method, {@code call} should no longer be used.
177179
*
180+
* <h3>Server errors</h3>
181+
* If the server completes the RPC with a non-OK status, a {@link StatusRuntimeException}
182+
* is thrown. The status code and trailers can be accessed from the exception.
183+
*
178184
* @return the single response message.
179185
* @throws StatusRuntimeException on error
180186
*/
@@ -190,6 +196,10 @@ public static <ReqT, RespT> RespT blockingUnaryCall(ClientCall<ReqT, RespT> call
190196
* Executes a unary call and blocks on the response. The {@code call} should not be already
191197
* started. After calling this method, {@code call} should no longer be used.
192198
*
199+
* <h3>Server errors</h3>
200+
* If the server completes the RPC with a non-OK status, a {@link StatusRuntimeException}
201+
* is thrown. The status code and trailers can be accessed from the exception.
202+
*
193203
* @return the single response message.
194204
* @throws StatusRuntimeException on error
195205
*/
@@ -228,7 +238,11 @@ public static <ReqT, RespT> RespT blockingUnaryCall(
228238
* response stream. The {@code call} should not be already started. After calling this method,
229239
* {@code call} should no longer be used.
230240
*
231-
* <p>The returned iterator may throw {@link StatusRuntimeException} on error.
241+
* <h3>Server errors</h3>
242+
* If the server completes the RPC with a non-OK status, the returned iterator will throw
243+
* a {@link StatusRuntimeException} when attempting to read the error response (e.g. in
244+
* {@link Iterator#hasNext} or {@link Iterator#next}). The status code and trailers can be
245+
* accessed from the exception.
232246
*
233247
* @return an iterator over the response stream.
234248
*/
@@ -245,7 +259,11 @@ public static <ReqT, RespT> Iterator<RespT> blockingServerStreamingCall(
245259
* response stream. The {@code call} should not be already started. After calling this method,
246260
* {@code call} should no longer be used.
247261
*
248-
* <p>The returned iterator may throw {@link StatusRuntimeException} on error.
262+
* <h3>Server errors</h3>
263+
* If the server completes the RPC with a non-OK status, the returned iterator will throw
264+
* a {@link StatusRuntimeException} when attempting to read the error response (e.g. in
265+
* {@link Iterator#hasNext} or {@link Iterator#next}). The status code and trailers can be
266+
* accessed from the exception.
249267
*
250268
* @return an iterator over the response stream.
251269
*/
@@ -264,6 +282,11 @@ public static <ReqT, RespT> Iterator<RespT> blockingServerStreamingCall(
264282
* {@code call} should not be already started. After calling this method, {@code call} should no
265283
* longer be used.
266284
*
285+
* <h3>Server errors</h3>
286+
* If the server completes the RPC with a non-OK status, the returned future will fail with
287+
* a {@link StatusRuntimeException}. The status code and trailers can be accessed from the
288+
* exception.
289+
*
267290
* @return a future for the single response message.
268291
*/
269292
public static <ReqT, RespT> ListenableFuture<RespT> futureUnaryCall(

0 commit comments

Comments
 (0)