@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1788") public abstract class ServerCallStreamObserver<V> extends CallStreamObserver<V>
CallStreamObserver to allows for interaction with call
cancellation events on the server side.
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 and interact with the server using a normal client stub.
| Constructor and Description |
|---|
ServerCallStreamObserver() |
| Modifier and Type | Method and Description |
|---|---|
void |
disableAutoRequest()
Swaps to manual flow control where no message will be delivered to
StreamObserver.onNext(Object) unless it is request()ed. |
abstract boolean |
isCancelled()
If
true indicates that the call has been cancelled by the remote peer. |
abstract void |
setCompression(String compression)
Sets the compression algorithm to use for the call.
|
abstract void |
setOnCancelHandler(Runnable onCancelHandler)
|
disableAutoInboundFlowControl, isReady, request, setMessageCompression, setOnReadyHandlerclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitonCompleted, onError, onNextpublic abstract boolean isCancelled()
true indicates that the call has been cancelled by the remote peer.
This method may safely be called concurrently from multiple threads.
public abstract void setOnCancelHandler(Runnable onCancelHandler)
Runnable that will be called if the calls isCancelled() state
changes from false to true. It is guaranteed that execution of the
Runnable are serialized with calls to the 'inbound' StreamObserver.
Note that the handler may be called some time after isCancelled() has transitioned
to true as other callbacks may still be executing in the 'inbound' observer.
Setting the onCancelHandler will suppress the on-cancel exception thrown by
StreamObserver.onNext(V).
onCancelHandler - to call when client has cancelled the call.public abstract void setCompression(String compression)
It is safe to call this even if the client does not support the compression format chosen. The implementation will handle negotiation with the client and may fall back to no compression.
compression - the compression algorithm to use.IllegalArgumentException - if the compressor name can not be found.public void disableAutoRequest()
StreamObserver.onNext(Object) unless it is request()ed.
It may only be called during the initial call to the application, before the service returns
its StreamObserver.
Note that for cases where the message is received before the service handler is invoked, this method will have no effect. This is true for:
MethodDescriptor.MethodType.UNARY operations.MethodDescriptor.MethodType.SERVER_STREAMING operations.This API is still a work in-progress and may change in the future.