public abstract class ServerCallStreamObserver<V> extends CallStreamObserver<V>
CallStreamObserverto allows for interaction with call cancellation events on the server side.
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|
|Modifier and Type||Method and Description|
Requests the peer to produce
Sets the compression algorithm to use for the call.
Sets message compression for subsequent calls to
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public abstract boolean isCancelled()
truewhen the call is cancelled and the server is encouraged to abort processing to save resources, since the client will not be processing any further methods. Cancellations can be caused by timeouts, explicit cancellation by client, network errors, and similar.
This method may safely be called concurrently from multiple threads.
public abstract void setOnCancelHandler(Runnable onCancelHandler)
Runnableto be called if the call is cancelled and the server is encouraged to abort processing to save resources, since the client will not process any further messages. Cancellations can be caused by timeouts, explicit cancellation by the client, network errors, etc.
It is guaranteed that execution of the
Runnable is serialized with calls to the
StreamObserver. That also means that the callback will be delayed if other
callbacks are running; if one of those other callbacks runs for a significant amount of time
it can poll
isCancelled(), which is not delayed.
This method may only be called during the initial call to the application, before the
service returns its
Setting the onCancelHandler will suppress the on-cancel exception thrown by
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
It may only be called during the initial call to the application, before the service returns
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:
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.
false, the runnable passed to
setOnReadyHandler(java.lang.Runnable) will be called after
isReady() transitions to
public abstract void setOnReadyHandler(Runnable onReadyHandler)
Runnablethat will be executed every time the stream
isReady()state changes from
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'
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
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
isReady() == false the normal expectations apply, so there would be
public abstract void request(int count)
countmore messages to be delivered to the 'inbound'
This method is safe to call from multiple threads without external synchronization.