public abstract class ClientCallStreamObserver<ReqT> extends CallStreamObserver<ReqT>
CallStreamObserver
that allows for lower-level interaction with
client calls. An instance of this class is obtained via ClientResponseObserver
, or by
manually casting the StreamObserver
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 and Description |
---|
ClientCallStreamObserver() |
Modifier and Type | Method and Description |
---|---|
abstract void |
cancel(String message,
Throwable cause)
Prevent any further processing for this
ClientCallStreamObserver . |
void |
disableAutoRequestWithInitial(int request)
Swaps to manual flow control where no message will be delivered to
StreamObserver.onNext(Object) unless it is request() ed. |
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)
|
disableAutoInboundFlowControl
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
onCompleted, onError, onNext
public abstract void cancel(@Nullable String message, @Nullable Throwable cause)
ClientCallStreamObserver
. No further messages
will be received. The server is informed of cancellations, but may not stop processing the
call. Cancelling an already
cancel()
ed ClientCallStreamObserver
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.
message
- if not null
, will appear as the description of the CANCELLED statuscause
- if not null
, will appear as the cause of the CANCELLED statuspublic void disableAutoRequestWithInitial(int request)
StreamObserver.onNext(Object)
unless it is request()
ed. Since request()
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()
.
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
.
isReady
in class CallStreamObserver<ReqT>
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
.
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 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.
setOnReadyHandler
in class CallStreamObserver<ReqT>
onReadyHandler
- to call when peer is ready to receive more messages.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.
request
in class CallStreamObserver<ReqT>
count
- more messagespublic abstract void setMessageCompression(boolean enable)
StreamObserver.onNext(V)
.setMessageCompression
in class CallStreamObserver<ReqT>
enable
- whether to enable compression.