public abstract class UnaryCallable<RequestT,ResponseT> extends Object
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.
| Modifier | Constructor and Description |
|---|---|
protected |
UnaryCallable() |
| Modifier and Type | Method and Description |
|---|---|
ResponseT |
call(RequestT request)
Same as
call(Object, ApiCallContext), with a null context. |
ResponseT |
call(RequestT request,
ApiCallContext context)
Perform a call synchronously.
|
com.google.api.core.ApiFuture<ResponseT> |
futureCall(RequestT request)
Same as
futureCall(Object, ApiCallContext), with a null context. |
abstract com.google.api.core.ApiFuture<ResponseT> |
futureCall(RequestT request,
ApiCallContext context)
Perform a call asynchronously.
|
UnaryCallable<RequestT,ResponseT> |
withDefaultCallContext(ApiCallContext defaultCallContext)
Returns a new
UnaryCallable with an ApiCallContext that is used as a default
when none is supplied in individual calls. |
public abstract com.google.api.core.ApiFuture<ResponseT> futureCall(RequestT request, ApiCallContext context)
context - ApiCallContext to make the call withApiFuture for the call resultpublic com.google.api.core.ApiFuture<ResponseT> futureCall(RequestT request)
futureCall(Object, ApiCallContext), with a null context.request - requestApiFuture for the call resultpublic ResponseT call(RequestT request, ApiCallContext context)
request - The request to send to the service.context - ApiCallContext to make the call withApiException - if there is any bad status in the response.RuntimeException - if there is any other exception unrelated to bad status.public ResponseT call(RequestT request)
call(Object, ApiCallContext), with a null context.request - The request to send to the service.ApiException - if there is any bad status in the response.RuntimeException - if there is any other exception unrelated to bad status.public UnaryCallable<RequestT,ResponseT> withDefaultCallContext(ApiCallContext defaultCallContext)
UnaryCallable with an ApiCallContext that is used as a default
when none is supplied in individual calls.defaultCallContext - the default ApiCallContext.