asio-grpc v3.1.0
Asynchronous gRPC with Asio/unified executors
agrpc::HealthCheckService Class Referencefinal

CompletionQueue-based implementation of grpc::HealthCheckServiceInterface. More...

#include <agrpc/health_check_service.hpp>

Inherits grpc::HealthCheckServiceInterface.

Public Member Functions

void SetServingStatus (const std::string &service_name, bool serving)
 Set or change the serving status of the given service_name. More...
 
void SetServingStatus (bool serving)
 Apply a serving status to all registered service names. More...
 
void Shutdown ()
 Set all registered service names to not serving and prevent future state changes. More...
 

Related Functions

(Note that these are not member functions.)

grpc::ServerBuilder & add_health_check_service (grpc::ServerBuilder &builder)
 Add a HealthCheckService to a grpc::Server More...
 
void start_health_check_service (agrpc::HealthCheckService &service, agrpc::GrpcContext &grpc_context)
 Start a previously added HealthCheckService. More...
 
void start_health_check_service (grpc::Server &server, agrpc::GrpcContext &grpc_context)
 Start a previously added HealthCheckService (grpc::Server overload) More...
 

Detailed Description

CompletionQueue-based implementation of grpc::HealthCheckServiceInterface.

This class is a drop-in replacement for the grpc::DefaultHealthCheckService. It should be added to a grpc::ServerBuilder using agrpc::add_health_check_service.

Motivation: grpc::DefaultHealthCheckService is implemented in terms of gRPC's generic callback API. Mixing callback services and CompletionQueue-based services in one grpc::Server significantly degrades performance.

Note
In order to use this class you must compile and link with health.proto. If your compiler does not support __has_include then you must also include health.grpc.pb.h before including agrpc/health_check_service.hpp.
Since
2.3.0

Member Function Documentation

◆ SetServingStatus() [1/2]

void agrpc::HealthCheckService::SetServingStatus ( const std::string &  service_name,
bool  serving 
)
inline

Set or change the serving status of the given service_name.

Thread-safe

◆ SetServingStatus() [2/2]

void agrpc::HealthCheckService::SetServingStatus ( bool  serving)
inline

Apply a serving status to all registered service names.

Thread-safe

◆ Shutdown()

void agrpc::HealthCheckService::Shutdown ( )
inline

Set all registered service names to not serving and prevent future state changes.

Thread-safe

Friends And Related Function Documentation

◆ add_health_check_service()

grpc::ServerBuilder & add_health_check_service ( grpc::ServerBuilder &  builder)
related

Add a HealthCheckService to a grpc::Server

Must be called before grpc::ServerBuilder.BuildAndStart() and the service must be started using agrpc::start_health_check_service afterwards. May only be called once for a given ServerBuilder.

Example:

std::unique_ptr<grpc::Server> server;
grpc::ServerBuilder builder;
agrpc::GrpcContext grpc_context{builder.AddCompletionQueue()};
agrpc::add_health_check_service(builder);
server = builder.BuildAndStart();
agrpc::start_health_check_service(*server, grpc_context);
Execution context based on grpc::CompletionQueue
Definition: grpc_context.hpp:50
Since
2.3.0

◆ start_health_check_service() [1/2]

void start_health_check_service ( agrpc::HealthCheckService service,
agrpc::GrpcContext grpc_context 
)
related

Start a previously added HealthCheckService.

Must be called after grpc::ServerBuilder.BuildAndStart(). The service must have been added using agrpc::add_health_check_service()`. May only be called once for a given HealthCheckService.

Does not contribute to the work tracking of the GrpcContext. May not be called concurrently with GrpcContext::run/poll.

Note
When using GrpcContext::run/poll_completion_queue then none of the member functions of the service may be used.
Since
2.3.0

◆ start_health_check_service() [2/2]

void start_health_check_service ( grpc::Server &  server,
agrpc::GrpcContext grpc_context 
)
related

Start a previously added HealthCheckService (grpc::Server overload)

The service must have been added using agrpc::add_health_check_service(). May only be called once for a given HealthCheckService.

Effectively performs:

auto* service = static_cast<agrpc::HealthCheckService*>(server.GetHealthCheckService());
agrpc::start_health_check_service(*service, grpc_context);
CompletionQueue-based implementation of grpc::HealthCheckServiceInterface.
Definition: health_check_service.hpp:56
Since
2.3.0