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
public abstract class UnaryCallable<RequestT,ResponseT> extends java.lang.ObjectA 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 Modifier Constructor Description protectedUnaryCallable()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description ResponseTcall(RequestT request)Same ascall(Object, ApiCallContext), with a null context.ResponseTcall(RequestT request, ApiCallContext context)Perform a call synchronously.com.google.api.core.ApiFuture<ResponseT>futureCall(RequestT request)Same asfutureCall(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 newUnaryCallablewith anApiCallContextthat is used as a default when none is supplied in individual calls.
-
-
-
Method Detail
-
futureCall
public abstract com.google.api.core.ApiFuture<ResponseT> futureCall(RequestT request, ApiCallContext context)
Perform a call asynchronously.- Parameters:
context-ApiCallContextto make the call with- Returns:
ApiFuturefor the call result
-
futureCall
public com.google.api.core.ApiFuture<ResponseT> futureCall(RequestT request)
Same asfutureCall(Object, ApiCallContext), with a null context.- Parameters:
request- request- Returns:
ApiFuturefor the call result
-
call
public ResponseT call(RequestT request, ApiCallContext context)
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.java.lang.RuntimeException- if there is any other exception unrelated to bad status.
-
call
public ResponseT call(RequestT request)
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.java.lang.RuntimeException- if there is any other exception unrelated to bad status.
-
withDefaultCallContext
public UnaryCallable<RequestT,ResponseT> withDefaultCallContext(ApiCallContext defaultCallContext)
Returns a newUnaryCallablewith anApiCallContextthat is used as a default when none is supplied in individual calls.- Parameters:
defaultCallContext- the defaultApiCallContext.
-
-