diff --git a/core/src/main/java/io/grpc/ClientCall.java b/core/src/main/java/io/grpc/ClientCall.java index 47bb8782ae..52f9a54ff4 100644 --- a/core/src/main/java/io/grpc/ClientCall.java +++ b/core/src/main/java/io/grpc/ClientCall.java @@ -63,9 +63,10 @@ import javax.annotation.Nullable; * {@link Status#CANCELLED CANCELLED}. Otherwise, {@link Listener#onClose Listener.onClose()} is * called with whatever status the RPC was finished. We ensure that at most one is called. * - *
Example: A simple Unary (1 request, 1 response) RPC would look like this: + *
- * call = channel.newCall(method, callOptions); + * call = channel.newCall(unaryMethod, callOptions); * call.start(listener, headers); * call.sendMessage(message); * call.halfClose(); @@ -73,6 +74,40 @@ import javax.annotation.Nullable; * // wait for listener.onMessage() ** + *
The following snippet demonstrates a bi-directional streaming case, where the client sends
+ * requests produced by a fictional makeNextRequest() in a flow-control-compliant
+ * manner, and notifies gRPC library to receive additional response after one is consumed by
+ * a fictional processResponse().
+ *
+ *
+ * call = channel.newCall(bidiStreamingMethod, callOptions);
+ * listener = new ClientCall.Listener<FooResponse>() {
+ * @Override
+ * public void onMessage(FooResponse response) {
+ * processResponse(response);
+ * // Notify gRPC to receive one additional response.
+ * call.request(1);
+ * }
+ *
+ * @Override
+ * public void onReady() {
+ * while (call.isReady()) {
+ * FooRequest nextRequest = makeNextRequest();
+ * if (nextRequest == null) { // No more requests to send
+ * call.halfClose();
+ * return;
+ * }
+ * call.sendMessage(makeNextRequest());
+ * }
+ * }
+ * }
+ * call.start(listener, headers);
+ * // Notify gRPC to receive one response. Without this line, onMessage() would never be called.
+ * call.request(1);
+ *
+ *
* @param