Package com.google.api.gax.rpc
Class UnaryCallable<RequestT,ResponseT>
java.lang.Object
com.google.api.gax.rpc.UnaryCallable<RequestT,ResponseT>
- Direct Known Subclasses:
BatchingCallable,PagedCallable,TracedBatchingCallable,TracedUnaryCallable,TranslatingUnaryCallable
A UnaryCallable is an immutable object which is capable of making RPC calls to non-streaming API
methods.
In typical usage, the request to send to the remote service will not be bound to the UnaryCallable, but instead is provided at call time, which allows for a UnaryCallable to be saved and used indefinitely.
There are two styles of calls that can be made through a UnaryCallable: synchronous and asynchronous.
Synchronous example:
RequestType request = RequestType.newBuilder().build();
UnaryCallable<RequestType, ResponseType> unaryCallable = api.doSomethingCallable();
ResponseType response = unaryCallable.call();
Asynchronous example:
RequestType request = RequestType.newBuilder().build();
UnaryCallable<RequestType, ResponseType> unaryCallable = api.doSomethingCallable();
ApiFuture<ResponseType> resultFuture = unaryCallable.futureCall();
// do other work
// ...
ResponseType response = resultFuture.get();
It is considered advanced usage for a user to create a UnaryCallable themselves. This class is intended to be created by a generated client class, and configured by instances of UnaryCallSettings.Builder which are exposed through the client settings class.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSame ascall(Object, ApiCallContext), with a null context.call(RequestT request, ApiCallContext context) Perform a call synchronously.futureCall(RequestT request) Same asfutureCall(Object, ApiCallContext), with a null context.futureCall(RequestT request, ApiCallContext context) Perform a call asynchronously.withDefaultCallContext(ApiCallContext defaultCallContext) Returns a newUnaryCallablewith anApiCallContextthat is used as a default when none is supplied in individual calls.
-
Constructor Details
-
UnaryCallable
protected UnaryCallable()
-
-
Method Details
-
futureCall
Perform a call asynchronously.- Parameters:
context-ApiCallContextto make the call with- Returns:
ApiFuturefor the call result
-
futureCall
Same asfutureCall(Object, ApiCallContext), with a null context.- Parameters:
request- request- Returns:
ApiFuturefor the call result
-
call
Perform a call synchronously.- Parameters:
request- The request to send to the service.context-ApiCallContextto make the call with- Returns:
- the call result
- Throws:
ApiException- if there is any bad status in the response.RuntimeException- if there is any other exception unrelated to bad status.
-
call
Same ascall(Object, ApiCallContext), with a null context.- Parameters:
request- The request to send to the service.- Returns:
- the call result
- Throws:
ApiException- if there is any bad status in the response.RuntimeException- if there is any other exception unrelated to bad status.
-
withDefaultCallContext
Returns a newUnaryCallablewith anApiCallContextthat is used as a default when none is supplied in individual calls.- Parameters:
defaultCallContext- the defaultApiCallContext.
-