TEC
A lightweight C++ library enabling safe, efficient execution in multithreaded and concurrent systems.
Loading...
Searching...
No Matches
tec::GrpcClient< TParams, Traits > Class Template Reference

Base class for actor-style asynchronous gRPC clients. More...

#include <tec_grpc_client.hpp>

Inheritance diagram for tec::GrpcClient< TParams, Traits >:
tec::Actor

Classes

struct  ChannelBuilder
 Holder for a function pointer that creates a gRPC channel. More...
 

Public Types

typedef Traits traits
 Traits providing all gRPC-related type aliases.
 
typedef TParams Params
 Configuration parameters type.
 
typedef traits::Service Service
 gRPC service stub type
 
typedef traits::Channel Channel
 gRPC channel type
 
typedef traits::Credentials Credentials
 credentials type
 
typedef traits::Arguments Arguments
 channel arguments type
 
typedef traits::CompressionAlgorithm CompressionAlgorithm
 compression enum type
 

Public Member Functions

 GrpcClient (const Params &params, const ChannelBuilder &channel_builder, const std::shared_ptr< Credentials > &credentials)
 Constructs a GrpcClient instance.
 
virtual ~GrpcClient ()=default
 Virtual destructor (defaulted)
 
void start (Signal *sig_started, Status *status) override
 Establishes connection to the gRPC server.
 
void shutdown (Signal *sig_stopped) override
 Graceful shutdown hook.
 
virtual Status process_request (Request request, Reply reply) override
 Processes a single request → reply pair.
 
- Public Member Functions inherited from tec::Actor
 Actor ()=default
 Default constructor.
 
 Actor (const Actor &)=delete
 Deleted copy constructor.
 
 Actor (Actor &&)=delete
 Deleted move constructor.
 
Actoroperator= (const Actor &)=delete
 Deleted copy assignment operator.
 
Actoroperator= (Actor &&)=delete
 Deleted move assignment operator.
 
virtual ~Actor ()=default
 Virtual destructor.
 
virtual Status run ()
 Mimics Daemon's behavior.
 
virtual Status terminate ()
 Mimics Daemon's behavior.
 

Protected Member Functions

virtual void set_channel_arguments ()
 Configures channel arguments before channel creation.
 

Protected Attributes

Params params_
 Runtime configuration parameters (address, timeouts, message size, compression, etc.)
 
std::shared_ptr< Credentialscredentials_
 Credentials object used to create secure/insecure channels.
 
std::unique_ptr< typename Service::Stub > stub_
 Owned stub instance — created after successful channel connection.
 
ChannelBuilder channel_builder_
 Channel creation functor (injected at construction)
 
std::shared_ptr< Channelchannel_
 Shared pointer to the active gRPC channel.
 
Arguments arguments_
 Channel creation arguments (message size limits, compression, keepalive, etc.)
 

Detailed Description

template<typename TParams, typename Traits>
class tec::GrpcClient< TParams, Traits >

Base class for actor-style asynchronous gRPC clients.

Provides common infrastructure for creating and managing a gRPC channel, configuring message size limits and compression, connecting with timeout, and creating a service stub.

Concrete clients should inherit from this class and implement process_request() to perform actual RPC calls.

Template Parameters
TParamsUser-defined parameter structure (must derive from GrpcClientParams)
TraitsInstance of grpc_client_traits<...> defining all gRPC-related types

Constructor & Destructor Documentation

◆ GrpcClient()

tec::GrpcClient< TParams, Traits >::GrpcClient ( const Params params,
const ChannelBuilder channel_builder,
const std::shared_ptr< Credentials > &  credentials 
)
inline

Constructs a GrpcClient instance.

Parameters
paramsConfiguration parameters (address, timeouts, limits…)
channel_builderFunctor responsible for creating the gRPC channel
credentialsCredentials to use (insecure / SSL / custom)

Member Function Documentation

◆ process_request()

virtual Status tec::GrpcClient< TParams, Traits >::process_request ( Request  request,
Reply  reply 
)
inlineoverridevirtual

Processes a single request → reply pair.

Pure virtual in the base class — must be implemented by derived classes. This is where actual RPC calls (unary, client-streaming, server-streaming, bidi) should be performed.

Parameters
requestInput request message
replyOutput reply message (to be filled)
Returns
Status Success or detailed error information

Implements tec::Actor.

◆ set_channel_arguments()

virtual void tec::GrpcClient< TParams, Traits >::set_channel_arguments ( )
inlineprotectedvirtual

Configures channel arguments before channel creation.

Called automatically during start(). Sets maximum send/receive message sizes and compression algorithm according to values in params_.

Can be overridden in derived classes to set additional channel arguments (e.g. keep-alive, HTTP/2 settings, custom interceptors, etc.).

◆ shutdown()

void tec::GrpcClient< TParams, Traits >::shutdown ( Signal sig_stopped)
inlineoverridevirtual

Graceful shutdown hook.

Currently only logs; derived classes may override to drain queues, cancel pending RPCs, etc.

Parameters
sig_stoppedSignal to notify when shutdown is complete

Implements tec::Actor.

◆ start()

void tec::GrpcClient< TParams, Traits >::start ( Signal sig_started,
Status status 
)
inlineoverridevirtual

Establishes connection to the gRPC server.

  1. Configures channel arguments
  2. Creates the channel using the injected ChannelBuilder
  3. Waits for connection with timeout
  4. Creates service stub on success
Parameters
sig_startedSignal to notify when initialization completes
status[out] Connection result status

Implements tec::Actor.


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