Class ClientCallStreamObserver<ReqT>
- java.lang.Object
-
- io.grpc.stub.CallStreamObserver<ReqT>
-
- io.grpc.stub.ClientCallStreamObserver<ReqT>
-
- All Implemented Interfaces:
StreamObserver<ReqT>
public abstract class ClientCallStreamObserver<ReqT> extends CallStreamObserver<ReqT>
A refinement ofCallStreamObserver
that allows for lower-level interaction with client calls. An instance of this class is obtained viaClientResponseObserver
, or by manually casting theStreamObserver
returned by a stub.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 make a fake for the server-side.
-
-
Constructor Summary
Constructors Constructor Description ClientCallStreamObserver()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
cancel(String message, Throwable cause)
Prevent any further processing for thisClientCallStreamObserver
.void
disableAutoRequestWithInitial(int request)
Swaps to manual flow control where no message will be delivered toStreamObserver.onNext(Object)
unless it isrequest()
ed.abstract boolean
isReady()
Iftrue
, indicates that the observer is capable of sending additional messages without requiring excessive buffering internally.abstract void
request(int count)
Requests the peer to producecount
more messages to be delivered to the 'inbound'StreamObserver
.abstract void
setMessageCompression(boolean enable)
Sets message compression for subsequent calls toStreamObserver.onNext(V)
.abstract void
setOnReadyHandler(Runnable onReadyHandler)
-
Methods inherited from class io.grpc.stub.CallStreamObserver
disableAutoInboundFlowControl
-
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
-
cancel
public abstract void cancel(@Nullable String message, @Nullable Throwable cause)
Prevent any further processing for thisClientCallStreamObserver
. No further messages will be received. The server is informed of cancellations, but may not stop processing the call. Cancelling an alreadycancel()
edClientCallStreamObserver
has no effect.No other methods on this class can be called after this method has been called.
It is recommended that at least one of the arguments to be non-
null
, to provide useful debug information. Both argument being null may log warnings and result in suboptimal performance. Also note that the provided information will not be sent to the server.- Parameters:
message
- if notnull
, will appear as the description of the CANCELLED statuscause
- if notnull
, will appear as the cause of the CANCELLED status
-
disableAutoRequestWithInitial
public void disableAutoRequestWithInitial(int request)
Swaps to manual flow control where no message will be delivered toStreamObserver.onNext(Object)
unless it isrequest()
ed. Sincerequest()
may not be called before the call is started, a number of initial requests may be specified.This method may only be called during
ClientResponseObserver.beforeStart()
.
-
isReady
public abstract boolean isReady()
Iftrue
, 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 tosetOnReadyHandler(java.lang.Runnable)
will be called afterisReady()
transitions totrue
.- Specified by:
isReady
in classCallStreamObserver<ReqT>
-
setOnReadyHandler
public abstract void setOnReadyHandler(Runnable onReadyHandler)
Set aRunnable
that will be executed every time the streamisReady()
state changes fromfalse
totrue
. While it is not guaranteed that the same thread will always be used to execute theRunnable
, it is guaranteed that executions are serialized with calls to the 'inbound'StreamObserver
.May only be called during
ClientResponseObserver.beforeStart(io.grpc.stub.ClientCallStreamObserver<ReqT>)
.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 checkingisReady()
's current value instead of assuming it is nowtrue
. IfisReady() == false
the normal expectations apply, so there would be anotheronReadyHandler
callback.- Specified by:
setOnReadyHandler
in classCallStreamObserver<ReqT>
- Parameters:
onReadyHandler
- to call when peer is ready to receive more messages.
-
request
public abstract void request(int count)
Requests the peer to producecount
more messages to be delivered to the 'inbound'StreamObserver
.This method is safe to call from multiple threads without external synchronization.
- Specified by:
request
in classCallStreamObserver<ReqT>
- Parameters:
count
- more messages
-
setMessageCompression
public abstract void setMessageCompression(boolean enable)
Sets message compression for subsequent calls toStreamObserver.onNext(V)
.- Specified by:
setMessageCompression
in classCallStreamObserver<ReqT>
- Parameters:
enable
- whether to enable compression.
-
-