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 ofCallStreamObserverthat allows for lower-level interaction with client calls. An instance of this class is obtained viaClientResponseObserver, or by manually casting theStreamObserverreturned 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 voidcancel(String message, Throwable cause)Prevent any further processing for thisClientCallStreamObserver.voiddisableAutoRequestWithInitial(int request)Swaps to manual flow control where no message will be delivered toStreamObserver.onNext(Object)unless it isrequest()ed.abstract booleanisReady()Iftrue, indicates that the observer is capable of sending additional messages without requiring excessive buffering internally.abstract voidrequest(int count)Requests the peer to producecountmore messages to be delivered to the 'inbound'StreamObserver.abstract voidsetMessageCompression(boolean enable)Sets message compression for subsequent calls toStreamObserver.onNext(V).abstract voidsetOnReadyHandler(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()edClientCallStreamObserverhas 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:
isReadyin classCallStreamObserver<ReqT>
-
setOnReadyHandler
public abstract void setOnReadyHandler(Runnable onReadyHandler)
Set aRunnablethat will be executed every time the streamisReady()state changes fromfalsetotrue. 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() == falsewithin this callback. Handle "spurious" notifications by checkingisReady()'s current value instead of assuming it is nowtrue. IfisReady() == falsethe normal expectations apply, so there would be anotheronReadyHandlercallback.- Specified by:
setOnReadyHandlerin 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 producecountmore messages to be delivered to the 'inbound'StreamObserver.This method is safe to call from multiple threads without external synchronization.
- Specified by:
requestin classCallStreamObserver<ReqT>- Parameters:
count- more messages
-
setMessageCompression
public abstract void setMessageCompression(boolean enable)
Sets message compression for subsequent calls toStreamObserver.onNext(V).- Specified by:
setMessageCompressionin classCallStreamObserver<ReqT>- Parameters:
enable- whether to enable compression.
-
-