Skip to content

Commit 916e848

Browse files
committed
Documenting error transmission and callback behavior.
1 parent 68b4f42 commit 916e848

File tree

2 files changed

+102
-8
lines changed

2 files changed

+102
-8
lines changed

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

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ private ClientCalls() {}
7070
*
7171
* <p>If the provided {@code responseObserver} is an instance of {@link ClientResponseObserver},
7272
* {@code beforeStart()} will be called.
73+
*
74+
* <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.
7380
*/
7481
public static <ReqT, RespT> void asyncUnaryCall(
7582
ClientCall<ReqT, RespT> call, ReqT req, StreamObserver<RespT> responseObserver) {
@@ -84,6 +91,13 @@ public static <ReqT, RespT> void asyncUnaryCall(
8491
*
8592
* <p>If the provided {@code responseObserver} is an instance of {@link ClientResponseObserver},
8693
* {@code beforeStart()} will be called.
94+
*
95+
* <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.
87101
*/
88102
public static <ReqT, RespT> void asyncServerStreamingCall(
89103
ClientCall<ReqT, RespT> call, ReqT req, StreamObserver<RespT> responseObserver) {
@@ -100,12 +114,23 @@ public static <ReqT, RespT> void asyncServerStreamingCall(
100114
* {@code beforeStart()} will be called.
101115
*
102116
* @return request stream observer. It will extend {@link ClientCallStreamObserver}
117+
*
118+
* <h3>Client errors</h3>
103119
* onError called on the request stream observer will result in stream cancellation. The response
104120
* {@link StreamObserver} will be immediately notified of the cancellation with a
105-
* {@link io.grpc.StatusRuntimeException}. The server's request stream observer will receive an
106-
* onError callbackk from the gRPC server framework with a {@link io.grpc.StatusRuntimeException}
107-
* for the cancellation. The actual exception passed by the client to onError is never actually
108-
* transmitted to the server.
121+
* {@link io.grpc.StatusRuntimeException} with the exception passed to onError set as the cause
122+
* 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
125+
* passed by the client to onError is never actually transmitted to the server and the server
126+
* just receives a RST_STREAM frame indicating cancellation by the client.
127+
*
128+
* <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.
109134
*/
110135
public static <ReqT, RespT> StreamObserver<ReqT> asyncClientStreamingCall(
111136
ClientCall<ReqT, RespT> call,
@@ -122,12 +147,23 @@ public static <ReqT, RespT> StreamObserver<ReqT> asyncClientStreamingCall(
122147
* {@code beforeStart()} will be called.
123148
*
124149
* @return request stream observer. It will extend {@link ClientCallStreamObserver}
150+
*
151+
* <h3>Client errors</h3>
125152
* onError called on the request stream observer will result in stream cancellation. The response
126153
* {@link StreamObserver} will be immediately notified of the cancellation with a
127-
* {@link io.grpc.StatusRuntimeException}. The server's request stream observer will receive an
128-
* onError callbackk from the gRPC server framework with a {@link io.grpc.StatusRuntimeException}
129-
* for the cancellation. The actual exception passed by the client to onError is never actually
130-
* transmitted to the server.
154+
* {@link io.grpc.StatusRuntimeException} with the exception passed to onError set as the cause
155+
* 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
158+
* passed by the client to onError is never actually transmitted to the server and the server
159+
* just receives a RST_STREAM frame indicating cancellation by the client.
160+
*
161+
* <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.
131167
*/
132168
public static <ReqT, RespT> StreamObserver<ReqT> asyncBidiStreamingCall(
133169
ClientCall<ReqT, RespT> call, StreamObserver<RespT> responseObserver) {

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import io.grpc.ServerCall;
2727
import io.grpc.ServerCallHandler;
2828
import io.grpc.Status;
29+
import io.grpc.StatusException;
30+
import io.grpc.StatusRuntimeException;
2931

3032
/**
3133
* Utility functions for adapting {@link ServerCallHandler}s to application service implementation,
@@ -45,6 +47,14 @@ private ServerCalls() {
4547
* Creates a {@link ServerCallHandler} for a unary call method of the service.
4648
*
4749
* @param method an adaptor to the actual method on the service implementation.
50+
* <p>
51+
* <h3>Server errors</h3>
52+
* If the throwable sent to the server's outbound {@link StreamObserver}'s onError
53+
* is a {@link StatusException} or {@link StatusRuntimeException}, that status code will be sent
54+
* and UNKNOWN status code otherwise. Its description will be encoded to the stream trailer, but
55+
* the cause (which may contain server application's information) will not. After the stream
56+
* trailer with END_STREAM is sent, the server side call is considered to be closed.
57+
* </p>
4858
*/
4959
public static <ReqT, RespT> ServerCallHandler<ReqT, RespT> asyncUnaryCall(
5060
UnaryMethod<ReqT, RespT> method) {
@@ -55,6 +65,22 @@ public static <ReqT, RespT> ServerCallHandler<ReqT, RespT> asyncUnaryCall(
5565
* Creates a {@link ServerCallHandler} for a server streaming method of the service.
5666
*
5767
* @param method an adaptor to the actual method on the service implementation.
68+
* <p>
69+
* <h3>Client errors</h3>
70+
* The server's request stream observer will receive an
71+
* onError callback with a {@link io.grpc.StatusRuntimeException} for the cancellation with the
72+
* message 'Client cancelled', and exception cause set to null because the actual exception
73+
* passed by the client to onError is never actually transmitted to the server and the server just
74+
* receives a RST_STREAM frame indicating cancellation by the client.
75+
* </p>
76+
* <p>
77+
* <h3>Server errors</h3>
78+
* If the throwable sent to the server's outbound {@link StreamObserver}'s onError
79+
* is a {@link StatusException} or {@link StatusRuntimeException}, that status code will be sent
80+
* and UNKNOWN status code otherwise. Its description will be encoded to the stream trailer, but
81+
* the cause (which may contain server application's information) will not. After the stream
82+
* trailer with END_STREAM is sent, the server side call is considered to be closed.
83+
* </p>
5884
*/
5985
public static <ReqT, RespT> ServerCallHandler<ReqT, RespT> asyncServerStreamingCall(
6086
ServerStreamingMethod<ReqT, RespT> method) {
@@ -65,6 +91,22 @@ public static <ReqT, RespT> ServerCallHandler<ReqT, RespT> asyncServerStreamingC
6591
* Creates a {@link ServerCallHandler} for a client streaming method of the service.
6692
*
6793
* @param method an adaptor to the actual method on the service implementation.
94+
* <p>
95+
* <h3>Client errors</h3>
96+
* The server's request stream observer will receive an
97+
* onError callback with a {@link io.grpc.StatusRuntimeException} for the cancellation with the
98+
* message 'Client cancelled', and exception cause set to null because the actual exception
99+
* passed by the client to onError is never actually transmitted to the server and the server just
100+
* receives a RST_STREAM frame indicating cancellation by the client.
101+
* </p>
102+
* <p>
103+
* <h3>Server errors</h3>
104+
* If the throwable sent to the server's outbound {@link StreamObserver}'s onError
105+
* is a {@link StatusException} or {@link StatusRuntimeException}, that status code will be sent
106+
* and UNKNOWN status code otherwise. Its description will be encoded to the stream trailer, but
107+
* the cause (which may contain server application's information) will not. After the stream
108+
* trailer with END_STREAM is sent, the server side call is considered to be closed.
109+
* </p>
68110
*/
69111
public static <ReqT, RespT> ServerCallHandler<ReqT, RespT> asyncClientStreamingCall(
70112
ClientStreamingMethod<ReqT, RespT> method) {
@@ -75,6 +117,22 @@ public static <ReqT, RespT> ServerCallHandler<ReqT, RespT> asyncClientStreamingC
75117
* Creates a {@link ServerCallHandler} for a bidi streaming method of the service.
76118
*
77119
* @param method an adaptor to the actual method on the service implementation.
120+
* <p>
121+
* <h3>Client errors</h3>
122+
* 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
125+
* passed by the client to onError is never actually transmitted to the server and the server just
126+
* receives a RST_STREAM frame indicating cancellation by the client.
127+
* </p>
128+
* <p>
129+
* <h3>Server errors</h3>
130+
* If the throwable sent to the server's outbound {@link StreamObserver}'s onError
131+
* is a {@link StatusException} or {@link StatusRuntimeException}, that status code will be sent
132+
* and UNKNOWN status code otherwise. Its description will be encoded to the stream trailer, but
133+
* the cause (which may contain server application's information) will not. After the stream
134+
* trailer with END_STREAM is sent, the server side call is considered to be closed.
135+
* </p>
78136
*/
79137
public static <ReqT, RespT> ServerCallHandler<ReqT, RespT> asyncBidiStreamingCall(
80138
BidiStreamingMethod<ReqT, RespT> method) {

0 commit comments

Comments
 (0)