Apache Mesos
Classes | Public Member Functions | List of all members
process::grpc::client::Runtime Class Reference

A copyable interface to manage an internal runtime process for asynchronous gRPC calls. More...

#include <grpc.hpp>

Public Member Functions

 Runtime ()
 
template<typename Method , typename Request = typename internal::MethodTraits<Method>::request_type, typename Response = typename internal::MethodTraits<Method>::response_type, typename std::enable_if< std::is_convertible< typename std::decay< Request >::type *, google::protobuf::Message * >::value, int >::type = 0>
Future< Try< Response, StatusError > > call (const Connection &connection, Method &&method, Request &&request, const CallOptions &options)
 Sends an asynchronous gRPC call. More...
 
void terminate ()
 Asks the internal runtime process to shut down the CompletionQueue, which would asynchronously drain and fail all pending gRPC calls in the CompletionQueue, then join the looper thread. More...
 
Future< Nothingwait ()
 

Detailed Description

A copyable interface to manage an internal runtime process for asynchronous gRPC calls.

A runtime process keeps a gRPC CompletionQueue to manage outstanding requests, a looper thread to wait for any incoming responses from the CompletionQueue, and handles the requests and responses. All Runtime copies share the same runtime process. Usually we only need a single runtime process to handle all gRPC calls, but multiple runtime processes can be instantiated for better parallelism and isolation.

NOTE: The caller must call terminate to drain the CompletionQueue before finalizing libprocess to gracefully terminate the gRPC runtime.

Constructor & Destructor Documentation

process::grpc::client::Runtime::Runtime ( )
inline

Member Function Documentation

template<typename Method , typename Request = typename internal::MethodTraits<Method>::request_type, typename Response = typename internal::MethodTraits<Method>::response_type, typename std::enable_if< std::is_convertible< typename std::decay< Request >::type *, google::protobuf::Message * >::value, int >::type = 0>
Future<Try<Response, StatusError> > process::grpc::client::Runtime::call ( const Connection connection,
Method &&  method,
Request &&  request,
const CallOptions options 
)
inline

Sends an asynchronous gRPC call.

This function returns a Future of a Try such that the response protobuf is returned only if the gRPC call returns an OK status to ensure type safety (see https://github.com/grpc/grpc/issues/12824). Note that the future never fails; it will return a StatusError if a non-OK status is returned for the call, so the caller can handle the error programmatically.

Parameters
connectionA connection to a gRPC server.
methodThe asynchronous gRPC call to make. This should be obtained by the GRPC_CLIENT_METHOD(service, rpc) macro.
requestThe request protobuf for the gRPC call.
optionsThe gRPC options for the call.
Returns
a Future of Try waiting for a response protobuf or an error.
void process::grpc::client::Runtime::terminate ( )

Asks the internal runtime process to shut down the CompletionQueue, which would asynchronously drain and fail all pending gRPC calls in the CompletionQueue, then join the looper thread.

Future<Nothing> process::grpc::client::Runtime::wait ( )
Returns
A Future waiting for all pending gRPC calls in the CompletionQueue of the internal runtime process to be drained and the looper thread to be joined.

The documentation for this class was generated from the following file: