Class ClientCalls.CallToStreamObserverAdapter<ReqT>

java.lang.Object
io.grpc.stub.CallStreamObserver<ReqT>
io.grpc.stub.ClientCallStreamObserver<ReqT>
io.grpc.stub.ClientCalls.CallToStreamObserverAdapter<ReqT>
All Implemented Interfaces:
StreamObserver<ReqT>
Enclosing class:
ClientCalls

private static final class ClientCalls.CallToStreamObserverAdapter<ReqT> extends ClientCallStreamObserver<ReqT>
  • Field Details

    • frozen

      private boolean frozen
    • call

      private final ClientCall<ReqT,?> call
    • streamingResponse

      private final boolean streamingResponse
    • onReadyHandler

      private Runnable onReadyHandler
    • initialRequest

      private int initialRequest
    • autoRequestEnabled

      private boolean autoRequestEnabled
    • aborted

      private boolean aborted
    • completed

      private boolean completed
  • Constructor Details

    • CallToStreamObserverAdapter

      CallToStreamObserverAdapter(ClientCall<ReqT,?> call, boolean streamingResponse)
  • Method Details

    • freeze

      private void freeze()
    • onNext

      public void onNext(ReqT value)
      Description copied from interface: StreamObserver
      Receives a value from the stream.

      Can be called many times but is never called after StreamObserver.onError(Throwable) or StreamObserver.onCompleted() are called.

      Unary calls must invoke onNext at most once. Clients may invoke onNext at most once for server streaming calls, but may receive many onNext callbacks. Servers may invoke onNext at most once for client streaming calls, but may receive many onNext callbacks.

      If an exception is thrown by an implementation the caller is expected to terminate the stream by calling StreamObserver.onError(Throwable) with the caught exception prior to propagating it.

      Parameters:
      value - the value passed to the stream
    • onError

      public void onError(Throwable t)
      Description copied from interface: StreamObserver
      Receives a terminating error from the stream.

      May only be called once and if called it must be the last method called. In particular if an exception is thrown by an implementation of onError no further calls to any method are allowed.

      t should be a StatusException or StatusRuntimeException, but other Throwable types are possible. Callers should generally convert from a Status via Status.asException() or Status.asRuntimeException(). Implementations should generally convert to a Status via Status.fromThrowable(Throwable).

      Parameters:
      t - the error occurred on the stream
    • onCompleted

      public void onCompleted()
      Description copied from interface: StreamObserver
      Receives a notification of successful stream completion.

      May only be called once and if called it must be the last method called. In particular if an exception is thrown by an implementation of onCompleted no further calls to any method are allowed.

    • isReady

      public boolean isReady()
      Description copied from class: ClientCallStreamObserver
      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 ClientCallStreamObserver.setOnReadyHandler(Runnable) will be called after isReady() transitions to true.

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

      public void setOnReadyHandler(Runnable onReadyHandler)
      Description copied from class: ClientCallStreamObserver
      Set a Runnable that will be executed every time the stream ClientCallStreamObserver.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(ClientCallStreamObserver).

      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 ClientCallStreamObserver<ReqT>
      Parameters:
      onReadyHandler - to call when peer is ready to receive more messages.
    • disableAutoInboundFlowControl

      public void disableAutoInboundFlowControl()
      Description copied from class: CallStreamObserver
      Disables automatic flow control where a token is returned to the peer after a call to the 'inbound' StreamObserver.onNext(Object) has completed. If disabled an application must make explicit calls to CallStreamObserver.request(int) to receive messages.

      On client-side this method may only be called during ClientResponseObserver.beforeStart(ClientCallStreamObserver). On server-side it may only be called during the initial call to the application, before the service returns its StreamObserver.

      Note that for cases where the runtime knows that only one inbound message is allowed calling this method will have no effect and the runtime will always permit one and only one message. This is true for:

      This API is being replaced, but is not yet deprecated. On server-side it being replaced with ServerCallStreamObserver.disableAutoRequest(). On client-side disableAutoRequestWithInitial(1).

      Specified by:
      disableAutoInboundFlowControl in class CallStreamObserver<ReqT>
    • disableAutoRequestWithInitial

      public void disableAutoRequestWithInitial(int request)
      Description copied from class: ClientCallStreamObserver
      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().

      Overrides:
      disableAutoRequestWithInitial in class ClientCallStreamObserver<ReqT>
    • request

      public void request(int count)
      Description copied from class: ClientCallStreamObserver
      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 ClientCallStreamObserver<ReqT>
      Parameters:
      count - more messages
    • setMessageCompression

      public void setMessageCompression(boolean enable)
      Description copied from class: ClientCallStreamObserver
      Sets message compression for subsequent calls to StreamObserver.onNext(V).
      Specified by:
      setMessageCompression in class ClientCallStreamObserver<ReqT>
      Parameters:
      enable - whether to enable compression.
    • cancel

      public void cancel(@Nullable String message, @Nullable Throwable cause)
      Description copied from class: ClientCallStreamObserver
      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.

      Specified by:
      cancel in class ClientCallStreamObserver<ReqT>
      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