Package io.grpc.stub

Class ClientCalls

java.lang.Object
io.grpc.stub.ClientCalls

public final class ClientCalls extends Object
Utility functions for processing different call idioms. We have one-to-one correspondence between utilities in this class and the potential signatures in a generated stub class so that the runtime can vary behavior without requiring regeneration of the stub.
  • Field Details

  • Constructor Details

    • ClientCalls

      private ClientCalls()
  • Method Details

    • asyncUnaryCall

      public static <ReqT, RespT> void asyncUnaryCall(ClientCall<ReqT,RespT> call, ReqT req, StreamObserver<RespT> responseObserver)
      Executes a unary call with a response StreamObserver. The call should not be already started. After calling this method, call should no longer be used.

      If the provided responseObserver is an instance of ClientResponseObserver, beforeStart() will be called.

    • asyncServerStreamingCall

      public static <ReqT, RespT> void asyncServerStreamingCall(ClientCall<ReqT,RespT> call, ReqT req, StreamObserver<RespT> responseObserver)
      Executes a server-streaming call with a response StreamObserver. The call should not be already started. After calling this method, call should no longer be used.

      If the provided responseObserver is an instance of ClientResponseObserver, beforeStart() will be called.

    • asyncClientStreamingCall

      public static <ReqT, RespT> StreamObserver<ReqT> asyncClientStreamingCall(ClientCall<ReqT,RespT> call, StreamObserver<RespT> responseObserver)
      Executes a client-streaming call returning a StreamObserver for the request messages. The call should not be already started. After calling this method, call should no longer be used.

      If the provided responseObserver is an instance of ClientResponseObserver, beforeStart() will be called.

      Returns:
      request stream observer. It will extend ClientCallStreamObserver
    • asyncBidiStreamingCall

      public static <ReqT, RespT> StreamObserver<ReqT> asyncBidiStreamingCall(ClientCall<ReqT,RespT> call, StreamObserver<RespT> responseObserver)
      Executes a bidirectional-streaming call. The call should not be already started. After calling this method, call should no longer be used.

      If the provided responseObserver is an instance of ClientResponseObserver, beforeStart() will be called.

      Returns:
      request stream observer. It will extend ClientCallStreamObserver
    • blockingUnaryCall

      public static <ReqT, RespT> RespT blockingUnaryCall(ClientCall<ReqT,RespT> call, ReqT req)
      Executes a unary call and blocks on the response. The call should not be already started. After calling this method, call should no longer be used.
      Returns:
      the single response message.
      Throws:
      StatusRuntimeException - on error
    • blockingUnaryCall

      public static <ReqT, RespT> RespT blockingUnaryCall(Channel channel, MethodDescriptor<ReqT,RespT> method, CallOptions callOptions, ReqT req)
      Executes a unary call and blocks on the response. The call should not be already started. After calling this method, call should no longer be used.
      Returns:
      the single response message.
      Throws:
      StatusRuntimeException - on error
    • blockingServerStreamingCall

      public static <ReqT, RespT> Iterator<RespT> blockingServerStreamingCall(ClientCall<ReqT,RespT> call, ReqT req)
      Executes a server-streaming call returning a blocking Iterator over the response stream. The call should not be already started. After calling this method, call should no longer be used.

      The returned iterator may throw StatusRuntimeException on error.

      Returns:
      an iterator over the response stream.
    • blockingServerStreamingCall

      public static <ReqT, RespT> Iterator<RespT> blockingServerStreamingCall(Channel channel, MethodDescriptor<ReqT,RespT> method, CallOptions callOptions, ReqT req)
      Executes a server-streaming call returning a blocking Iterator over the response stream. The call should not be already started. After calling this method, call should no longer be used.

      The returned iterator may throw StatusRuntimeException on error.

      Returns:
      an iterator over the response stream.
    • futureUnaryCall

      public static <ReqT, RespT> com.google.common.util.concurrent.ListenableFuture<RespT> futureUnaryCall(ClientCall<ReqT,RespT> call, ReqT req)
      Executes a unary call and returns a ListenableFuture to the response. The call should not be already started. After calling this method, call should no longer be used.
      Returns:
      a future for the single response message.
    • getUnchecked

      private static <V> V getUnchecked(Future<V> future)
      Returns the result of calling Future.get() interruptibly on a task known not to throw a checked exception.

      If interrupted, the interrupt is restored before throwing an exception..

      Throws:
      CancellationException - if get throws a CancellationException.
      StatusRuntimeException - if get throws an ExecutionException or an InterruptedException.
    • toStatusRuntimeException

      private static StatusRuntimeException toStatusRuntimeException(Throwable t)
      Wraps the given Throwable in a StatusRuntimeException. If it contains an embedded StatusException or StatusRuntimeException, the returned exception will contain the embedded trailers and status, with the given exception as the cause. Otherwise, an exception will be generated from an Status.UNKNOWN status.
    • cancelThrow

      private static RuntimeException cancelThrow(ClientCall<?,?> call, Throwable t)
      Cancels a call, and throws the exception.
      Parameters:
      t - must be a RuntimeException or Error
    • asyncUnaryRequestCall

      private static <ReqT, RespT> void asyncUnaryRequestCall(ClientCall<ReqT,RespT> call, ReqT req, StreamObserver<RespT> responseObserver, boolean streamingResponse)
    • asyncUnaryRequestCall

      private static <ReqT, RespT> void asyncUnaryRequestCall(ClientCall<ReqT,RespT> call, ReqT req, ClientCalls.StartableListener<RespT> responseListener)
    • asyncStreamingRequestCall

      private static <ReqT, RespT> StreamObserver<ReqT> asyncStreamingRequestCall(ClientCall<ReqT,RespT> call, StreamObserver<RespT> responseObserver, boolean streamingResponse)
    • startCall

      private static <ReqT, RespT> void startCall(ClientCall<ReqT,RespT> call, ClientCalls.StartableListener<RespT> responseListener)