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

Base class for actor-style gRPC servers. More...

#include <tec_grpc_server.hpp>

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

Public Types

typedef TParams Params
 Configuration parameters type.
 
typedef Traits::Service Service
 gRPC service type
 
typedef Traits::RpcServer RpcServer
 running server instance type
 
typedef Traits::Builder Builder
 server builder type
 
typedef Traits::Credentials Credentials
 server credentials type
 
typedef Traits::CompressionAlgorithm CompressionAlgorithm
 compression algorithm enum
 
typedef Traits::CompressionLevel CompressionLevel
 compression level enum
 

Public Member Functions

 GrpcServer (const Params &params, const std::shared_ptr< Credentials > &credentials)
 Constructs a GrpcServer instance.
 
virtual ~GrpcServer ()=default
 Virtual destructor (defaulted)
 
Status process_request (Request, Reply) override
 Synchronous request processor (optional override).
 
void start (Signal *sig_started, Status *status) override
 Starts the gRPC server and begins listening.
 
void shutdown (Signal *sig_stopped) override
 Initiates graceful shutdown of the server.
 
- 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_plugins ()
 Configures optional gRPC server plugins (reflection, health checking).
 
virtual void set_builder_options (Builder &builder)
 Configures server-wide options on the ServerBuilder.
 

Protected Attributes

Params params_
 Runtime configuration parameters (listen address, message size, compression, plugins…)
 
std::unique_ptr< RpcServerserver_
 Owned server instance — created and started during start()
 
std::shared_ptr< Credentialscredentials_
 Server-side credentials (insecure / SSL / custom)
 

Detailed Description

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

Base class for actor-style gRPC servers.

Provides common infrastructure for:

  • configuring server builder (message size limits, compression)
  • enabling optional features (health checking, reflection)
  • starting a listening server with timeout-protected startup
  • graceful shutdown

Concrete servers should inherit from this class and implement process_request() if synchronous request handling is needed, or override start() / use async service registration patterns.

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

Constructor & Destructor Documentation

◆ GrpcServer()

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

Constructs a GrpcServer instance.

Parameters
paramsServer configuration (listen address, limits, compression…)
credentialsServer-side credentials (for TLS or other authentication)

Member Function Documentation

◆ process_request()

Status tec::GrpcServer< TParams, Traits >::process_request ( Request  ,
Reply   
)
inlineoverridevirtual

Synchronous request processor (optional override).

Default implementation returns NotImplemented. May be overridden in derived classes that implement a synchronous service pattern.

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

Implements tec::Actor.

◆ set_builder_options()

virtual void tec::GrpcServer< TParams, Traits >::set_builder_options ( Builder builder)
inlineprotectedvirtual

Configures server-wide options on the ServerBuilder.

Called automatically during start(). Sets maximum message sizes and default compression settings according to values in params_.

Can be overridden in derived classes to set additional builder options (e.g. keep-alive, resource quotas, custom interceptors, etc.).

Parameters
builderThe ServerBuilder instance being configured

◆ set_plugins()

virtual void tec::GrpcServer< TParams, Traits >::set_plugins ( )
inlineprotectedvirtual

Configures optional gRPC server plugins (reflection, health checking).

Called automatically during start(). Enables server reflection and/or gRPC health checking if the corresponding builder functions were provided in params_.

Can be overridden in derived classes to register additional interceptors, authentication/authorization plugins, etc.

◆ shutdown()

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

Initiates graceful shutdown of the server.

Triggers server shutdown (stops accepting new connections, allows existing RPCs to finish within deadline).

Parameters
sig_stoppedSignal to set when shutdown procedure has been completed

Implements tec::Actor.

◆ start()

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

Starts the gRPC server and begins listening.

Sequence:

  1. Configures optional plugins (health, reflection)
  2. Creates and configures ServerBuilder
  3. Adds listening port with credentials
  4. Registers the service instance
  5. Builds and starts the server
  6. Waits for shutdown signal (blocking call)
Parameters
sig_startedSignal to set when server is successfully listening
status[out] Startup result status

Implements tec::Actor.


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