V
- type of outbound message.@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/8499") public abstract class CallStreamObserver<V> extends Object implements StreamObserver<V>
In any call there are logically four StreamObserver
implementations:
StreamObserver
to send messages to the server.
StreamObserver
to send messages (responses) to the client.
Implementations of this class represent the 'outbound' message streams. The client-side
one is ClientCallStreamObserver
and the service-side one is
ServerCallStreamObserver
.
Like StreamObserver
, implementations are not required to be thread-safe; if multiple
threads will be writing to an instance concurrently, the application must synchronize its calls.
DO NOT MOCK: The API is too complex to reliably mock. Use InProcessChannelBuilder to create "real" RPCs suitable for testing.
Constructor and Description |
---|
CallStreamObserver() |
Modifier and Type | Method and Description |
---|---|
abstract void |
disableAutoInboundFlowControl()
Disables automatic flow control where a token is returned to the peer after a call
to the 'inbound'
StreamObserver.onNext(Object) has completed. |
abstract boolean |
isReady()
If
true , indicates that the observer is capable of sending additional messages
without requiring excessive buffering internally. |
abstract void |
request(int count)
Requests the peer to produce
count more messages to be delivered to the 'inbound'
StreamObserver . |
abstract void |
setMessageCompression(boolean enable)
Sets message compression for subsequent calls to
StreamObserver.onNext(V) . |
abstract void |
setOnReadyHandler(Runnable onReadyHandler)
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
onCompleted, onError, onNext
public abstract boolean isReady()
true
, indicates that the observer is capable of sending additional messages
without requiring excessive buffering internally. This value is just a suggestion and the
application is free to ignore it, however doing so may result in excessive buffering within the
observer.
If false
, the runnable passed to setOnReadyHandler(java.lang.Runnable)
will be called after
isReady()
transitions to true
.
public abstract void setOnReadyHandler(Runnable onReadyHandler)
Runnable
that will be executed every time the stream isReady()
state
changes from false
to true
. While it is not guaranteed that the same
thread will always be used to execute the Runnable
, it is guaranteed that executions
are serialized with calls to the 'inbound' StreamObserver
.
On client-side this method may only be called during ClientResponseObserver.beforeStart(io.grpc.stub.ClientCallStreamObserver<ReqT>)
. On server-side it may only be called during the initial
call to the application, before the service returns its StreamObserver
.
Because there is a processing delay to deliver this notification, it is possible for
concurrent writes to cause isReady() == false
within this callback. Handle "spurious"
notifications by checking isReady()
's current value instead of assuming it is now
true
. If isReady() == false
the normal expectations apply, so there would be
another onReadyHandler
callback.
onReadyHandler
- to call when peer is ready to receive more messages.public abstract void disableAutoInboundFlowControl()
StreamObserver.onNext(Object)
has completed. If disabled
an application must make explicit calls to request(int)
to receive messages.
On client-side this method may only be called during ClientResponseObserver.beforeStart(io.grpc.stub.ClientCallStreamObserver<ReqT>)
. On server-side it may only be called during the initial
call to the application, before the service returns its StreamObserver
.
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:
MethodDescriptor.MethodType.UNARY
operations on both the
client and server.
MethodDescriptor.MethodType.CLIENT_STREAMING
operations on the client.
MethodDescriptor.MethodType.SERVER_STREAMING
operations on the server.
This API is being replaced, but is not yet deprecated. On server-side it being replaced
with ServerCallStreamObserver.disableAutoRequest()
. On client-side disableAutoRequestWithInitial(1)
.
public abstract void request(int count)
count
more messages to be delivered to the 'inbound'
StreamObserver
.
This method is safe to call from multiple threads without external synchronization.
count
- more messagespublic abstract void setMessageCompression(boolean enable)
StreamObserver.onNext(V)
.enable
- whether to enable compression.