Skip to content

Commit 813a53b

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

2 files changed

Lines changed: 96 additions & 88 deletions

File tree

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

Lines changed: 32 additions & 30 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) {

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

Lines changed: 64 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
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;
3129

3230
/**
3331
* Utility functions for adapting {@link ServerCallHandler}s to application service implementation,
@@ -47,14 +45,6 @@ private ServerCalls() {
4745
* Creates a {@link ServerCallHandler} for a unary call method of the service.
4846
*
4947
* @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>
5848
*/
5949
public static <ReqT, RespT> ServerCallHandler<ReqT, RespT> asyncUnaryCall(
6050
UnaryMethod<ReqT, RespT> method) {
@@ -65,22 +55,6 @@ public static <ReqT, RespT> ServerCallHandler<ReqT, RespT> asyncUnaryCall(
6555
* Creates a {@link ServerCallHandler} for a server streaming method of the service.
6656
*
6757
* @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>
8458
*/
8559
public static <ReqT, RespT> ServerCallHandler<ReqT, RespT> asyncServerStreamingCall(
8660
ServerStreamingMethod<ReqT, RespT> method) {
@@ -91,22 +65,6 @@ public static <ReqT, RespT> ServerCallHandler<ReqT, RespT> asyncServerStreamingC
9165
* Creates a {@link ServerCallHandler} for a client streaming method of the service.
9266
*
9367
* @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>
11068
*/
11169
public static <ReqT, RespT> ServerCallHandler<ReqT, RespT> asyncClientStreamingCall(
11270
ClientStreamingMethod<ReqT, RespT> method) {
@@ -117,22 +75,6 @@ public static <ReqT, RespT> ServerCallHandler<ReqT, RespT> asyncClientStreamingC
11775
* Creates a {@link ServerCallHandler} for a bidi streaming method of the service.
11876
*
11977
* @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>
13678
*/
13779
public static <ReqT, RespT> ServerCallHandler<ReqT, RespT> asyncBidiStreamingCall(
13880
BidiStreamingMethod<ReqT, RespT> method) {
@@ -143,27 +85,91 @@ public static <ReqT, RespT> ServerCallHandler<ReqT, RespT> asyncBidiStreamingCal
14385
* Adaptor to a unary call method.
14486
*/
14587
public interface UnaryMethod<ReqT, RespT> extends UnaryRequestMethod<ReqT, RespT> {
88+
/**
89+
* Invoke the method.
90+
*
91+
* @param request the request message from the client
92+
* @param responseObserver the observer to receive the single response. Calling {@code
93+
* responseObserver}'s {@link StreamObserver#onCompleted} or {@link
94+
* StreamObserver#onError} is the end of the RPC. {@code onCompleted()} will close the RPC
95+
* with status code OK. {@code onError()} will convert the Throwable to a Status with {@link
96+
* Status#fromThrowable} and trailers with {@link Status#trailersFromThrowable}. The {@link
97+
* Status#getCause} is not sent to the client, except if done by an interceptor. Callers
98+
* generally create a Throwable with {@link Status#asException()}, {@link
99+
* Status#asException(Metadata)}, {@link Status#asRuntimeException()}, or {@link
100+
* Status#asRuntimeException(Metadata)}.
101+
*/
146102
@Override void invoke(ReqT request, StreamObserver<RespT> responseObserver);
147103
}
148104

149105
/**
150106
* Adaptor to a server streaming method.
151107
*/
152108
public interface ServerStreamingMethod<ReqT, RespT> extends UnaryRequestMethod<ReqT, RespT> {
109+
/**
110+
* Invoke the method.
111+
*
112+
* @param request the request message from the client
113+
* @param responseObserver the observer to receive the response stream. Calling {@code
114+
* responseObserver}'s {@link StreamObserver#onCompleted} or {@link
115+
* StreamObserver#onError} is the end of the RPC. {@code onCompleted()} will close the RPC
116+
* with status code OK. {@code onError()} will convert the Throwable to a Status with {@link
117+
* Status#fromThrowable} and trailers with {@link Status#trailersFromThrowable}. The {@link
118+
* Status#getCause} is not sent to the client, except if done by an interceptor. Callers
119+
* generally create a Throwable with {@link Status#asException()}, {@link
120+
* Status#asException(Metadata)}, {@link Status#asRuntimeException()}, or {@link
121+
* Status#asRuntimeException(Metadata)}.
122+
*/
153123
@Override void invoke(ReqT request, StreamObserver<RespT> responseObserver);
154124
}
155125

156126
/**
157127
* Adaptor to a client streaming method.
158128
*/
159129
public interface ClientStreamingMethod<ReqT, RespT> extends StreamingRequestMethod<ReqT, RespT> {
130+
/**
131+
* Invoke the method.
132+
*
133+
* <h3>Client errors</h3>
134+
* The Throwable received by the server's request stream observer when converted to a status
135+
* with Status.fromThrowable(), always has the status code CANCELLED.
136+
*
137+
* @param responseObserver the observer to receive the single response. Calling {@code
138+
* responseObserver}'s {@link StreamObserver#onCompleted} or {@link
139+
* StreamObserver#onError} is the end of the RPC. {@code onCompleted()} will close the RPC
140+
* with status code OK. {@code onError()} will convert the Throwable to a Status with {@link
141+
* Status#fromThrowable} and trailers with {@link Status#trailersFromThrowable}. The {@link
142+
* Status#getCause} is not sent to the client, except if done by an interceptor. Callers
143+
* generally create a Throwable with {@link Status#asException()}, {@link
144+
* Status#asException(Metadata)}, {@link Status#asRuntimeException()}, or {@link
145+
* Status#asRuntimeException(Metadata)}.
146+
* @return a stream observer for receiving the request stream from the client
147+
*/
160148
@Override StreamObserver<ReqT> invoke(StreamObserver<RespT> responseObserver);
161149
}
162150

163151
/**
164152
* Adaptor to a bidirectional streaming method.
165153
*/
166154
public interface BidiStreamingMethod<ReqT, RespT> extends StreamingRequestMethod<ReqT, RespT> {
155+
/**
156+
* Invoke the method.
157+
*
158+
* <h3>Client errors</h3>
159+
* The Throwable received by the server's request stream observer when converted to a status
160+
* with Status.fromThrowable(), always has the status code CANCELLED.
161+
*
162+
* @param responseObserver the observer to receive the response stream. Calling {@code
163+
* responseObserver}'s {@link StreamObserver#onCompleted} or {@link
164+
* StreamObserver#onError} is the end of the RPC. {@code onCompleted()} will close the RPC
165+
* with status code OK. {@code onError()} will convert the Throwable to a Status with {@link
166+
* Status#fromThrowable} and trailers with {@link Status#trailersFromThrowable}. The {@link
167+
* Status#getCause} is not sent to the client, except if done by an interceptor. Callers
168+
* generally create a Throwable with {@link Status#asException()}, {@link
169+
* Status#asException(Metadata)}, {@link Status#asRuntimeException()}, or {@link
170+
* Status#asRuntimeException(Metadata)}.
171+
* @return a stream observer for receiving the request stream from the client
172+
*/
167173
@Override StreamObserver<ReqT> invoke(StreamObserver<RespT> responseObserver);
168174
}
169175

0 commit comments

Comments
 (0)