Class ClientCalls
java.lang.Object
io.grpc.stub.ClientCalls
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classConvert events on aClientCall.Listenerinto a blockingIterator.private static final classprivate static final classprivate static classprivate static final class(package private) static enumprivate static final classprivate static final classCompletes aClientCalls.GrpcFutureusingStreamObserverevents. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Logger(package private) static boolean(package private) static final CallOptions.Key<ClientCalls.StubType> InternalCallOptions.Keyto indicate stub types. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <ReqT,RespT>
StreamObserver<ReqT> asyncBidiStreamingCall(ClientCall<ReqT, RespT> call, StreamObserver<RespT> responseObserver) Executes a bidirectional-streaming call.static <ReqT,RespT>
StreamObserver<ReqT> asyncClientStreamingCall(ClientCall<ReqT, RespT> call, StreamObserver<RespT> responseObserver) Executes a client-streaming call returning aStreamObserverfor the request messages.static <ReqT,RespT>
voidasyncServerStreamingCall(ClientCall<ReqT, RespT> call, ReqT req, StreamObserver<RespT> responseObserver) Executes a server-streaming call with a responseStreamObserver.private static <ReqT,RespT>
StreamObserver<ReqT> asyncStreamingRequestCall(ClientCall<ReqT, RespT> call, StreamObserver<RespT> responseObserver, boolean streamingResponse) static <ReqT,RespT>
voidasyncUnaryCall(ClientCall<ReqT, RespT> call, ReqT req, StreamObserver<RespT> responseObserver) Executes a unary call with a responseStreamObserver.private static <ReqT,RespT>
voidasyncUnaryRequestCall(ClientCall<ReqT, RespT> call, ReqT req, ClientCalls.StartableListener<RespT> responseListener) private static <ReqT,RespT>
voidasyncUnaryRequestCall(ClientCall<ReqT, RespT> call, ReqT req, StreamObserver<RespT> responseObserver, boolean streamingResponse) static <ReqT,RespT>
Iterator<RespT> blockingServerStreamingCall(Channel channel, MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, ReqT req) Executes a server-streaming call returning a blockingIteratorover the response stream.static <ReqT,RespT>
Iterator<RespT> blockingServerStreamingCall(ClientCall<ReqT, RespT> call, ReqT req) Executes a server-streaming call returning a blockingIteratorover the response stream.static <ReqT,RespT>
RespTblockingUnaryCall(Channel channel, MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, ReqT req) Executes a unary call and blocks on the response.static <ReqT,RespT>
RespTblockingUnaryCall(ClientCall<ReqT, RespT> call, ReqT req) Executes a unary call and blocks on the response.private static RuntimeExceptioncancelThrow(ClientCall<?, ?> call, Throwable t) Cancels a call, and throws the exception.static <ReqT,RespT>
com.google.common.util.concurrent.ListenableFuture<RespT> futureUnaryCall(ClientCall<ReqT, RespT> call, ReqT req) Executes a unary call and returns aListenableFutureto the response.private static <V> VgetUnchecked(Future<V> future) Returns the result of callingFuture.get()interruptibly on a task known not to throw a checked exception.private static <ReqT,RespT>
voidstartCall(ClientCall<ReqT, RespT> call, ClientCalls.StartableListener<RespT> responseListener) private static StatusRuntimeExceptionWraps the givenThrowablein aStatusRuntimeException.
-
Field Details
-
logger
-
rejectRunnableOnExecutor
static boolean rejectRunnableOnExecutor -
STUB_TYPE_OPTION
InternalCallOptions.Keyto indicate stub types.
-
-
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 responseStreamObserver. Thecallshould not be already started. After calling this method,callshould no longer be used.If the provided
responseObserveris an instance ofClientResponseObserver,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 responseStreamObserver. Thecallshould not be already started. After calling this method,callshould no longer be used.If the provided
responseObserveris an instance ofClientResponseObserver,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 aStreamObserverfor the request messages. Thecallshould not be already started. After calling this method,callshould no longer be used.If the provided
responseObserveris an instance ofClientResponseObserver,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. Thecallshould not be already started. After calling this method,callshould no longer be used.If the provided
responseObserveris an instance ofClientResponseObserver,beforeStart()will be called.- Returns:
- request stream observer. It will extend
ClientCallStreamObserver
-
blockingUnaryCall
Executes a unary call and blocks on the response. Thecallshould not be already started. After calling this method,callshould 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. Thecallshould not be already started. After calling this method,callshould 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 blockingIteratorover the response stream. Thecallshould not be already started. After calling this method,callshould no longer be used.The returned iterator may throw
StatusRuntimeExceptionon 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 blockingIteratorover the response stream. Thecallshould not be already started. After calling this method,callshould no longer be used.The returned iterator may throw
StatusRuntimeExceptionon 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 aListenableFutureto the response. Thecallshould not be already started. After calling this method,callshould no longer be used.- Returns:
- a future for the single response message.
-
getUnchecked
Returns the result of callingFuture.get()interruptibly on a task known not to throw a checked exception.If interrupted, the interrupt is restored before throwing an exception..
- Throws:
CancellationException- ifgetthrows aCancellationException.StatusRuntimeException- ifgetthrows anExecutionExceptionor anInterruptedException.
-
toStatusRuntimeException
Wraps the givenThrowablein aStatusRuntimeException. If it contains an embeddedStatusExceptionorStatusRuntimeException, the returned exception will contain the embedded trailers and status, with the given exception as the cause. Otherwise, an exception will be generated from anStatus.UNKNOWNstatus. -
cancelThrow
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)
-