Class ServerCallStreamObserver<V>
- java.lang.Object
-
- io.grpc.stub.CallStreamObserver<V>
-
- io.grpc.stub.ServerCallStreamObserver<V>
-
- All Implemented Interfaces:
StreamObserver<V>
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1788") public abstract class ServerCallStreamObserver<V> extends CallStreamObserver<V>
A refinement ofCallStreamObserverto 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 Summary
Constructors Constructor Description ServerCallStreamObserver()
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description abstract booleanisCancelled()Iftrueindicates that the call has been cancelled by the remote peer.abstract voidsetCompression(java.lang.String compression)Sets the compression algorithm to use for the call.abstract voidsetOnCancelHandler(java.lang.Runnable onCancelHandler)-
Methods inherited from class io.grpc.stub.CallStreamObserver
disableAutoInboundFlowControl, isReady, request, setMessageCompression, setOnReadyHandler
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.grpc.stub.StreamObserver
onCompleted, onError, onNext
-
-
-
-
Method Detail
-
isCancelled
public abstract boolean isCancelled()
Iftrueindicates that the call has been cancelled by the remote peer.This method may safely be called concurrently from multiple threads.
-
setOnCancelHandler
public abstract void setOnCancelHandler(java.lang.Runnable onCancelHandler)
Set aRunnablethat will be called if the callsisCancelled()state changes fromfalsetotrue. It is guaranteed that execution of theRunnableare serialized with calls to the 'inbound'StreamObserver.Note that the handler may be called some time after
isCancelled()has transitioned totrueas other callbacks may still be executing in the 'inbound' observer.Setting the onCancelHandler will suppress the on-cancel exception thrown by
StreamObserver.onNext(V).- Parameters:
onCancelHandler- to call when client has cancelled the call.
-
setCompression
public abstract void setCompression(java.lang.String compression)
Sets the compression algorithm to use for the call. May only be called before sending any messages. Default gRPC servers support the "gzip" compressor.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.
- Parameters:
compression- the compression algorithm to use.- Throws:
java.lang.IllegalArgumentException- if the compressor name can not be found.
-
-