diff --git a/stub/src/main/java/io/grpc/stub/CallStreamObserver.java b/stub/src/main/java/io/grpc/stub/CallStreamObserver.java new file mode 100644 index 0000000000..512d0903fa --- /dev/null +++ b/stub/src/main/java/io/grpc/stub/CallStreamObserver.java @@ -0,0 +1,102 @@ +/* + * Copyright 2016, Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package io.grpc.stub; + +import io.grpc.ExperimentalApi; + +/** + * A refinement of StreamObserver provided by the GRPC runtime to the application that allows for + * more complex interactions with call behavior. + * + *
In any call there are logically two {@link StreamObserver} implementations: + *
Implementations of this class represent the 'outbound' message stream.
+ *
+ */
+@ExperimentalApi
+public abstract class CallStreamObserver Note that the handler may be called some time after {@link #isReady} has transitioned to
+ * true as other callbacks may still be executing in the 'inbound' observer.
+ *
+ * @param onReadyHandler to call when peer is ready to receive more messages.
+ */
+ public abstract void setOnReadyHandler(Runnable onReadyHandler);
+
+ /**
+ * Disables automatic flow control where a token is returned to the peer after a call
+ * to the 'inbound' {@link io.grpc.stub.StreamObserver#onNext(Object)} has completed. If disabled
+ * an application must make explicit calls to {@link #request} to receive messages.
+ *
+ * Note that for cases where the runtime knows that only one inbound message is allowed
+ * calling this method will have no effect and the runtime will always permit one and only
+ * one message. This is true for:
+ *
+ *
+ *
Note that the handler may be called some time after {@link #isCancelled} has transitioned to
+ * {@code true} as other callbacks may still be executing in the 'inbound' observer.
+ *
+ * @param onCancelHandler to call when client has cancelled the call.
+ */
+ public abstract void setOnCancelHandler(Runnable onCancelHandler);
+}
diff --git a/stub/src/main/java/io/grpc/stub/ServerCalls.java b/stub/src/main/java/io/grpc/stub/ServerCalls.java
index e01de42fa1..94c99970e0 100644
--- a/stub/src/main/java/io/grpc/stub/ServerCalls.java
+++ b/stub/src/main/java/io/grpc/stub/ServerCalls.java
@@ -128,9 +128,11 @@ public class ServerCalls {
MethodDescriptor