Go to the documentation of this file.
27 #include "absl/memory/memory.h"
39 #define MAX_SERVICE_NAME_LENGTH 200
99 std::shared_ptr<HealthCheckServiceImpl::CallHandler>
handler) {
109 const std::shared_ptr<HealthCheckServiceImpl::CallHandler>&
handler) {
115 if (service_data.
Unused()) {
122 std::unique_ptr<ServerCompletionQueue>
cq) {
136 call_handler->SendHealth(call_handler ,
status);
141 std::shared_ptr<HealthCheckServiceImpl::CallHandler>
handler) {
146 const std::shared_ptr<HealthCheckServiceImpl::CallHandler>&
handler) {
155 const char kHealthCheckMethodName[] =
"/grpc.health.v1.Health/Check";
156 const char kHealthWatchMethodName[] =
"/grpc.health.v1.Health/Watch";
161 std::unique_ptr<ServerCompletionQueue>
cq)
170 thread_ = absl::make_unique<grpc_core::Thread>(
"grpc_health_check_service",
188 CheckCallHandler::CreateAndStart(
cq_.get(), database_,
this);
189 WatchCallHandler::CreateAndStart(
cq_.get(), database_,
this);
212 if (!
request.DumpToSingleSlice(&
slice).ok())
return false;
213 uint8_t* request_bytes =
nullptr;
214 size_t request_size = 0;
216 request_size =
slice.size();
220 reinterpret_cast<char*
>(request_bytes), request_size,
arena.ptr());
221 if (request_struct ==
nullptr) {
245 response_struct,
arena.ptr(), &buf_length);
246 if (
buf ==
nullptr) {
251 ByteBuffer response_buffer(&encoded_response, 1);
264 std::shared_ptr<CallHandler>
self =
269 if (
service->shutdown_)
return;
273 std::placeholders::_1, std::placeholders::_2),
317 std::placeholders::_1, std::placeholders::_2),
322 writer_.FinishWithError(
status, &next_);
345 std::shared_ptr<CallHandler>
self =
350 if (
service->shutdown_)
return;
354 std::placeholders::_1, std::placeholders::_2),
360 std::placeholders::_1, std::placeholders::_2),
383 GPR_ASSERT(on_done_notified_.ReleaseHandler() !=
nullptr);
397 "[HCS %p] Health watch started for service \"%s\" (handler: %p)",
407 if (send_in_flight_) {
417 send_in_flight_ =
true;
433 std::placeholders::_1, std::placeholders::_2),
445 send_in_flight_ =
false;
449 auto status = pending_status_;
457 if (finish_called_)
return;
467 std::placeholders::_1, std::placeholders::_2),
470 finish_called_ =
true;
477 "[HCS %p] Health watch call finished (service_name: \"%s\", "
491 "[HCS %p] Health watch call is notified done (handler: %p, "
492 "is_cancelled: %d).",
grpc_completion_queue * cq_
void SendHealthLocked(std::shared_ptr< CallHandler > self, ServingStatus status)
static const Status & CANCELLED
A CANCELLED pre-defined instance.
std::unique_ptr< HealthCheckServiceImpl > impl_
std::unique_ptr< grpc::ClientReaderInterface< OrcaLoadReport > > stream_
ServingStatus GetServingStatus() const
void RegisterCallHandler(const std::string &service_name, std::shared_ptr< HealthCheckServiceImpl::CallHandler > handler)
void OnCallReceived(std::shared_ptr< CallHandler > self, bool ok)
void UnregisterCallHandler(const std::string &service_name, const std::shared_ptr< HealthCheckServiceImpl::CallHandler > &handler)
static void CreateAndStart(ServerCompletionQueue *cq, DefaultHealthCheckService *database, HealthCheckServiceImpl *service)
HealthCheckServiceImpl * GetHealthCheckService(std::unique_ptr< ServerCompletionQueue > cq)
grpc_core::ScopedArenaPtr arena
static bool DecodeRequest(const ByteBuffer &request, std::string *service_name)
DefaultHealthCheckService * database_
@ grpc_health_v1_HealthCheckResponse_SERVICE_UNKNOWN
@ grpc_health_v1_HealthCheckResponse_SERVING
UPB_INLINE char * grpc_health_v1_HealthCheckResponse_serialize(const grpc_health_v1_HealthCheckResponse *msg, upb_Arena *arena, size_t *len)
Server side rpc method class.
std::unique_ptr< grpc_core::Thread > thread_
std::map< std::string, ServiceData > services_map_
static void CreateAndStart(ServerCompletionQueue *cq, DefaultHealthCheckService *database, HealthCheckServiceImpl *service)
struct grpc_health_v1_HealthCheckResponse grpc_health_v1_HealthCheckResponse
DefaultHealthCheckService()
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
void OnFinishDone(std::shared_ptr< CallHandler > self, bool ok)
UPB_INLINE grpc_health_v1_HealthCheckRequest * grpc_health_v1_HealthCheckRequest_parse(const char *buf, size_t size, upb_Arena *arena)
static void * tag(intptr_t t)
void OnCallReceived(std::shared_ptr< CallHandler > self, bool ok)
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
void AddCallHandler(std::shared_ptr< HealthCheckServiceImpl::CallHandler > handler)
std::string service_name_
void SendHealth(std::shared_ptr< CallHandler > self, ServingStatus status) override
HealthCheckServiceImpl(DefaultHealthCheckService *database, std::unique_ptr< ServerCompletionQueue > cq)
static const Status & OK
An OK pre-defined instance.
CheckCallHandler(ServerCompletionQueue *cq, DefaultHealthCheckService *database, HealthCheckServiceImpl *service)
ServingStatus GetServingStatus(const std::string &service_name) const
std::unique_ptr< ServerCompletionQueue > cq_
void OnFinishDone(std::shared_ptr< CallHandler > self, bool ok)
~HealthCheckServiceImpl() override
void SetServingStatus(ServingStatus status)
WatchCallHandler(ServerCompletionQueue *cq, DefaultHealthCheckService *database, HealthCheckServiceImpl *service)
void SendFinishLocked(std::shared_ptr< CallHandler > self, const Status &status)
GPRAPI grpc_slice grpc_slice_from_copied_buffer(const char *source, size_t len)
std::set< std::shared_ptr< HealthCheckServiceImpl::CallHandler > > call_handlers_
void SendFinish(std::shared_ptr< CallHandler > self, const Status &status)
UPB_INLINE upb_StringView grpc_health_v1_HealthCheckRequest_service(const grpc_health_v1_HealthCheckRequest *msg)
void RemoveCallHandler(const std::shared_ptr< HealthCheckServiceImpl::CallHandler > &handler)
UPB_INLINE grpc_health_v1_HealthCheckResponse * grpc_health_v1_HealthCheckResponse_new(upb_Arena *arena)
void OnDoneNotified(std::shared_ptr< CallHandler > self, bool ok)
GRPC_CUSTOM_UTIL_STATUS Status
#define MAX_SERVICE_NAME_LENGTH
@ grpc_health_v1_HealthCheckResponse_NOT_SERVING
struct grpc_health_v1_HealthCheckRequest grpc_health_v1_HealthCheckRequest
void OnSendHealthDone(std::shared_ptr< CallHandler > self, bool ok)
UPB_INLINE void grpc_health_v1_HealthCheckResponse_set_status(grpc_health_v1_HealthCheckResponse *msg, int32_t value)
void AddMethod(internal::RpcServiceMethod *method)
static void Serve(void *arg)
__attribute__((deprecated("Please use GRPCProtoMethod."))) @interface ProtoMethod NSString * service
void StartServingThread()
static bool EncodeResponse(ServingStatus status, ByteBuffer *response)
static grpc_completion_queue * cq
std::unique_ptr< grpc::testing::TestServiceImpl > service_
void SetServingStatus(const std::string &service_name, bool serving) override
Set or change the serving status of the given service_name.
std::unique_ptr< std::thread > thread_
grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:09