Package io.grpc.stub

Class ClientCallStreamObserver<ReqT>

  • All Implemented Interfaces:
    StreamObserver<ReqT>

    public abstract class ClientCallStreamObserver<ReqT>
    extends CallStreamObserver<ReqT>
    A refinement of 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 Detail

      • ClientCallStreamObserver

        public ClientCallStreamObserver()
    • Method Detail

      • cancel

        public abstract void cancel​(@Nullable
                                    String message,
                                    @Nullable
                                    Throwable cause)
        Prevent any further processing for this 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.

        Parameters:
        message - if not null, will appear as the description of the CANCELLED status
        cause - if not null, 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 to 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().

      • isReady

        public abstract boolean isReady()
        If 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.

        Specified by:
        isReady in class CallStreamObserver<ReqT>
      • setOnReadyHandler

        public abstract void setOnReadyHandler​(Runnable onReadyHandler)
        Set a 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.

        Specified by:
        setOnReadyHandler in class CallStreamObserver<ReqT>
        Parameters:
        onReadyHandler - to call when peer is ready to receive more messages.
      • request

        public abstract void request​(int count)
        Requests the peer to produce count 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 class CallStreamObserver<ReqT>
        Parameters:
        count - more messages