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 {
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);
149 class WatchCallHandler :
public CallHandler {
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);
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,
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_;
238 bool serving)
override;
246 std::unique_ptr<ServerCompletionQueue> cq);
256 std::shared_ptr<HealthCheckServiceImpl::CallHandler> handler);
257 void RemoveCallHandler(
258 const std::shared_ptr<HealthCheckServiceImpl::CallHandler>& handler);
259 bool Unused()
const {
260 return call_handlers_.empty() && status_ ==
NOT_FOUND;
265 std::set<std::shared_ptr<HealthCheckServiceImpl::CallHandler>>
269 void RegisterCallHandler(
271 std::shared_ptr<HealthCheckServiceImpl::CallHandler> handler);
273 void UnregisterCallHandler(
275 const std::shared_ptr<HealthCheckServiceImpl::CallHandler>& handler);
278 bool shutdown_ =
false;
279 std::map<grpc::string, ServiceData> services_map_;
280 std::unique_ptr<HealthCheckServiceImpl> impl_;
285 #endif // GRPC_INTERNAL_CPP_SERVER_DEFAULT_HEALTH_CHECK_SERVICE_H
std::string string
Definition: config.h:35
::grpc_impl::ServerAsyncResponseWriter< ByteBuffer > GenericServerAsyncResponseWriter
Definition: async_generic_service.h:34
Desriptor of an RPC service and its various RPC methods.
Definition: service_type.h:60
void SetServingStatus(const grpc::string &service_name, bool serving) override
Set or change the serving status of the given service_name.
Definition: default_health_check_service.cc:41
Definition: async_unary_call_impl.h:301
void Shutdown() override
Set all registered service names to not serving and prevent future state changes. ...
Definition: default_health_check_service.cc:63
::grpc_impl::ServerContext ServerContext
Definition: server_context.h:26
::google::protobuf::util::Status Status
Definition: config_protobuf.h:90
void StartServingThread()
Definition: default_health_check_service.cc:174
::grpc_impl::ServerCompletionQueue ServerCompletionQueue
Definition: completion_queue.h:27
Definition: default_health_check_service.h:46
Definition: default_health_check_service.h:43
::grpc_impl::ServerAsyncWriter< ByteBuffer > GenericServerAsyncWriter
Definition: async_generic_service.h:37
The gRPC server uses this interface to expose the health checking service without depending on protob...
Definition: health_check_service_interface_impl.h:28
~HealthCheckServiceImpl()
Definition: default_health_check_service.cc:164
void RequestAsyncUnary(int index, ::grpc_impl::ServerContext *context, Message *request, internal::ServerAsyncStreamingInterface *stream, ::grpc_impl::CompletionQueue *call_cq, ::grpc_impl::ServerCompletionQueue *notification_cq, void *tag)
Definition: service_type.h:149
This header provides an object that reads bytes directly from a grpc::ByteBuffer, via the ZeroCopyInp...
Definition: alarm.h:24
#define GPR_ASSERT(x)
abort() the process if x is zero, having written a line to the log.
Definition: log.h:94
ServingStatus
Definition: default_health_check_service.h:43
void RequestAsyncServerStreaming(int index, ::grpc_impl::ServerContext *context, Message *request, internal::ServerAsyncStreamingInterface *stream, ::grpc_impl::CompletionQueue *call_cq, ::grpc_impl::ServerCompletionQueue *notification_cq, void *tag)
Definition: service_type.h:172
DefaultHealthCheckService()
Definition: default_health_check_service.cc:37
ServingStatus GetServingStatus(const grpc::string &service_name) const
Definition: default_health_check_service.cc:76
Definition: default_health_check_service.h:49
Definition: default_health_check_service.h:43
Definition: default_health_check_service.h:41
HealthCheckServiceImpl * GetHealthCheckService(std::unique_ptr< ServerCompletionQueue > cq)
Definition: default_health_check_service.cc:111
Definition: default_health_check_service.h:43
virtual ~CallHandler()=default
virtual void SendHealth(std::shared_ptr< CallHandler > self, ServingStatus status)=0
HealthCheckServiceImpl(DefaultHealthCheckService *database, std::unique_ptr< ServerCompletionQueue > cq)
Definition: default_health_check_service.cc:149