Class UnaryCallable<RequestT,​ResponseT>

  • Direct Known Subclasses:
    BatchingCallable, PagedCallable, TracedBatchingCallable, TracedUnaryCallable, TranslatingUnaryCallable

    public abstract class UnaryCallable<RequestT,​ResponseT>
    extends java.lang.Object
    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 Detail

      • UnaryCallable

        protected UnaryCallable()
    • Method Detail

      • futureCall

        public abstract com.google.api.core.ApiFuture<ResponseT> futureCall​(RequestT request,
                                                                            ApiCallContext context)
        Perform a call asynchronously.
        Parameters:
        context - ApiCallContext to make the call with
        Returns:
        ApiFuture for 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 - ApiCallContext to 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 as call(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.