19 #ifndef GRPC_INTERNAL_CPP_SERVER_DEFAULT_HEALTH_CHECK_SERVICE_H
20 #define GRPC_INTERNAL_CPP_SERVER_DEFAULT_HEALTH_CHECK_SERVICE_H
52 virtual void SendHealth(std::shared_ptr<CallHandler>
self,
57 std::unique_ptr<ServerCompletionQueue> cq);
73 using HandlerFunction =
74 std::function<void(std::shared_ptr<CallHandler>,
bool)>;
78 CallableTag(HandlerFunction func, std::shared_ptr<CallHandler> handler)
79 : handler_function_(
std::move(func)), handler_(
std::move(handler)) {
89 handler_function_(std::move(handler_), ok);
93 std::shared_ptr<CallHandler> ReleaseHandler() {
94 return std::move(handler_);
98 HandlerFunction handler_function_ =
nullptr;
99 std::shared_ptr<CallHandler> handler_;
106 class CheckCallHandler :
public CallHandler {
111 static void CreateAndStart(ServerCompletionQueue* cq,
117 CheckCallHandler(ServerCompletionQueue* cq,
122 void SendHealth(std::shared_ptr<CallHandler> ,
128 void OnCallReceived(std::shared_ptr<CallHandler>
self,
bool ok);
131 void OnFinishDone(std::shared_ptr<CallHandler>
self,
bool ok);
134 ServerCompletionQueue* cq_;
149 class WatchCallHandler :
public CallHandler {
154 static void CreateAndStart(ServerCompletionQueue* cq,
160 WatchCallHandler(ServerCompletionQueue* cq,
164 void SendHealth(std::shared_ptr<CallHandler>
self,
170 void OnCallReceived(std::shared_ptr<CallHandler>
self,
bool ok);
173 void SendHealthLocked(std::shared_ptr<CallHandler>
self,
177 void OnSendHealthDone(std::shared_ptr<CallHandler>
self,
bool ok);
179 void SendFinish(std::shared_ptr<CallHandler>
self,
const Status& status);
182 void SendFinishLocked(std::shared_ptr<CallHandler>
self,
186 void OnFinishDone(std::shared_ptr<CallHandler>
self,
bool ok);
189 void OnDoneNotified(std::shared_ptr<CallHandler>
self,
bool ok);
192 ServerCompletionQueue* cq_;
197 std::string service_name_;
202 bool send_in_flight_ =
false;
205 bool finish_called_ =
false;
207 CallableTag on_done_notified_;
208 CallableTag on_finish_done_;
212 static void Serve(
void* arg);
215 static bool DecodeRequest(
const ByteBuffer& request,
216 std::string* service_name);
217 static bool EncodeResponse(
ServingStatus status, ByteBuffer* response);
226 std::unique_ptr<ServerCompletionQueue> cq_;
231 std::atomic_bool shutdown_{
false};
232 std::unique_ptr<::grpc_core::Thread> thread_;
237 void SetServingStatus(
const std::string& service_name,
bool serving)
override;
245 std::unique_ptr<ServerCompletionQueue> cq);
255 std::shared_ptr<HealthCheckServiceImpl::CallHandler> handler);
256 void RemoveCallHandler(
257 const std::shared_ptr<HealthCheckServiceImpl::CallHandler>& handler);
258 bool Unused()
const {
259 return call_handlers_.empty() && status_ ==
NOT_FOUND;
264 std::set<std::shared_ptr<HealthCheckServiceImpl::CallHandler>>
268 void RegisterCallHandler(
269 const std::string& service_name,
270 std::shared_ptr<HealthCheckServiceImpl::CallHandler> handler);
272 void UnregisterCallHandler(
273 const std::string& service_name,
274 const std::shared_ptr<HealthCheckServiceImpl::CallHandler>& handler);
277 bool shutdown_ =
false;
278 std::map<std::string, ServiceData> services_map_;
279 std::unique_ptr<HealthCheckServiceImpl> impl_;
Definition: default_health_check_service.h:49
virtual ~CallHandler()=default
virtual void SendHealth(std::shared_ptr< CallHandler > self, ServingStatus status)=0
Definition: default_health_check_service.h:46
void StartServingThread()
Definition: default_health_check_service.cc:178
~HealthCheckServiceImpl() override
Definition: default_health_check_service.cc:168
HealthCheckServiceImpl(DefaultHealthCheckService *database, std::unique_ptr< ServerCompletionQueue > cq)
Definition: default_health_check_service.cc:153
Definition: default_health_check_service.h:41
DefaultHealthCheckService()
Definition: default_health_check_service.cc:41
void SetServingStatus(const std::string &service_name, bool serving) override
Set or change the serving status of the given service_name.
Definition: default_health_check_service.cc:45
HealthCheckServiceImpl * GetHealthCheckService(std::unique_ptr< ServerCompletionQueue > cq)
Definition: default_health_check_service.cc:115
void Shutdown() override
Set all registered service names to not serving and prevent future state changes.
Definition: default_health_check_service.cc:67
ServingStatus
Definition: default_health_check_service.h:43
@ SERVING
Definition: default_health_check_service.h:43
@ NOT_SERVING
Definition: default_health_check_service.h:43
@ NOT_FOUND
Definition: default_health_check_service.h:43
ServingStatus GetServingStatus(const std::string &service_name) const
Definition: default_health_check_service.cc:80
The gRPC server uses this interface to expose the health checking service without depending on protob...
Definition: health_check_service_interface.h:31
Desriptor of an RPC service and its various RPC methods.
Definition: service_type.h:56
void RequestAsyncUnary(int index, ::grpc::ServerContext *context, Message *request, internal::ServerAsyncStreamingInterface *stream, ::grpc::CompletionQueue *call_cq, ::grpc::ServerCompletionQueue *notification_cq, void *tag)
Definition: service_type.h:103
void RequestAsyncServerStreaming(int index, ::grpc::ServerContext *context, Message *request, internal::ServerAsyncStreamingInterface *stream, ::grpc::CompletionQueue *call_cq, ::grpc::ServerCompletionQueue *notification_cq, void *tag)
Definition: service_type.h:126
#define GPR_ASSERT(x)
abort() the process if x is zero, having written a line to the log.
Definition: log.h:92
::google::protobuf::util::Status Status
Definition: config_protobuf.h:91
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
ServerAsyncWriter< ByteBuffer > GenericServerAsyncWriter
Definition: async_generic_service.h:37
ServerAsyncResponseWriter< ByteBuffer > GenericServerAsyncResponseWriter
Definition: async_generic_service.h:35
Definition: async_unary_call.h:398