aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--BUILD9
-rw-r--r--CMakeLists.txt6
-rw-r--r--Makefile6
-rw-r--r--build.yaml3
-rw-r--r--include/grpc++/ext/health_check_service_server_builder_option.h5
-rw-r--r--include/grpc++/health_check_service_interface.h63
-rw-r--r--include/grpc++/server.h9
-rw-r--r--src/cpp/ext/health_check_service_server_builder_option.cc12
-rw-r--r--src/cpp/server/default_health_check_service.cc67
-rw-r--r--src/cpp/server/default_health_check_service.h59
-rw-r--r--src/cpp/server/health_check_service.cc (renamed from include/grpc++/ext/health_check_service_interface.h)23
-rw-r--r--src/cpp/server/server_cc.cc33
-rw-r--r--tools/doxygen/Doxyfile.c++.internal3
-rw-r--r--tools/run_tests/generated/sources_and_headers.json4
-rw-r--r--vsprojects/vcxproj/grpc++/grpc++.vcxproj5
-rw-r--r--vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters9
-rw-r--r--vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj5
-rw-r--r--vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters9
18 files changed, 302 insertions, 28 deletions
diff --git a/BUILD b/BUILD
index fcd2742a8f..be1e23007b 100644
--- a/BUILD
+++ b/BUILD
@@ -1374,6 +1374,7 @@ cc_library(
"src/cpp/server/secure_server_credentials.h",
"src/cpp/client/create_channel_internal.h",
"src/cpp/common/channel_filter.h",
+ "src/cpp/server/default_health_check_service.h",
"src/cpp/server/dynamic_thread_pool.h",
"src/cpp/server/thread_pool_interface.h",
"src/cpp/thread_manager/thread_manager.h",
@@ -1402,7 +1403,9 @@ cc_library(
"src/cpp/common/version_cc.cc",
"src/cpp/server/async_generic_service.cc",
"src/cpp/server/create_default_thread_pool.cc",
+ "src/cpp/server/default_health_check_service.cc",
"src/cpp/server/dynamic_thread_pool.cc",
+ "src/cpp/server/health_check_service.cc",
"src/cpp/server/server_builder.cc",
"src/cpp/server/server_cc.cc",
"src/cpp/server/server_context.cc",
@@ -1525,6 +1528,7 @@ cc_library(
srcs = [
"src/cpp/client/create_channel_internal.h",
"src/cpp/common/channel_filter.h",
+ "src/cpp/server/default_health_check_service.h",
"src/cpp/server/dynamic_thread_pool.h",
"src/cpp/server/thread_pool_interface.h",
"src/cpp/thread_manager/thread_manager.h",
@@ -1695,7 +1699,9 @@ cc_library(
"src/cpp/common/version_cc.cc",
"src/cpp/server/async_generic_service.cc",
"src/cpp/server/create_default_thread_pool.cc",
+ "src/cpp/server/default_health_check_service.cc",
"src/cpp/server/dynamic_thread_pool.cc",
+ "src/cpp/server/health_check_service.cc",
"src/cpp/server/server_builder.cc",
"src/cpp/server/server_cc.cc",
"src/cpp/server/server_context.cc",
@@ -2023,6 +2029,7 @@ cc_library(
srcs = [
"src/cpp/client/create_channel_internal.h",
"src/cpp/common/channel_filter.h",
+ "src/cpp/server/default_health_check_service.h",
"src/cpp/server/dynamic_thread_pool.h",
"src/cpp/server/thread_pool_interface.h",
"src/cpp/thread_manager/thread_manager.h",
@@ -2046,7 +2053,9 @@ cc_library(
"src/cpp/common/version_cc.cc",
"src/cpp/server/async_generic_service.cc",
"src/cpp/server/create_default_thread_pool.cc",
+ "src/cpp/server/default_health_check_service.cc",
"src/cpp/server/dynamic_thread_pool.cc",
+ "src/cpp/server/health_check_service.cc",
"src/cpp/server/server_builder.cc",
"src/cpp/server/server_cc.cc",
"src/cpp/server/server_context.cc",
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e90e8426cc..049f7fdaca 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1091,7 +1091,9 @@ add_library(grpc++
src/cpp/common/version_cc.cc
src/cpp/server/async_generic_service.cc
src/cpp/server/create_default_thread_pool.cc
+ src/cpp/server/default_health_check_service.cc
src/cpp/server/dynamic_thread_pool.cc
+ src/cpp/server/health_check_service.cc
src/cpp/server/server_builder.cc
src/cpp/server/server_cc.cc
src/cpp/server/server_context.cc
@@ -1252,7 +1254,9 @@ add_library(grpc++_cronet
src/cpp/common/version_cc.cc
src/cpp/server/async_generic_service.cc
src/cpp/server/create_default_thread_pool.cc
+ src/cpp/server/default_health_check_service.cc
src/cpp/server/dynamic_thread_pool.cc
+ src/cpp/server/health_check_service.cc
src/cpp/server/server_builder.cc
src/cpp/server/server_cc.cc
src/cpp/server/server_context.cc
@@ -1636,7 +1640,9 @@ add_library(grpc++_unsecure
src/cpp/common/version_cc.cc
src/cpp/server/async_generic_service.cc
src/cpp/server/create_default_thread_pool.cc
+ src/cpp/server/default_health_check_service.cc
src/cpp/server/dynamic_thread_pool.cc
+ src/cpp/server/health_check_service.cc
src/cpp/server/server_builder.cc
src/cpp/server/server_cc.cc
src/cpp/server/server_context.cc
diff --git a/Makefile b/Makefile
index 45d3cb2963..63f5d2ad31 100644
--- a/Makefile
+++ b/Makefile
@@ -3785,7 +3785,9 @@ LIBGRPC++_SRC = \
src/cpp/common/version_cc.cc \
src/cpp/server/async_generic_service.cc \
src/cpp/server/create_default_thread_pool.cc \
+ src/cpp/server/default_health_check_service.cc \
src/cpp/server/dynamic_thread_pool.cc \
+ src/cpp/server/health_check_service.cc \
src/cpp/server/server_builder.cc \
src/cpp/server/server_cc.cc \
src/cpp/server/server_context.cc \
@@ -3975,7 +3977,9 @@ LIBGRPC++_CRONET_SRC = \
src/cpp/common/version_cc.cc \
src/cpp/server/async_generic_service.cc \
src/cpp/server/create_default_thread_pool.cc \
+ src/cpp/server/default_health_check_service.cc \
src/cpp/server/dynamic_thread_pool.cc \
+ src/cpp/server/health_check_service.cc \
src/cpp/server/server_builder.cc \
src/cpp/server/server_cc.cc \
src/cpp/server/server_context.cc \
@@ -4686,7 +4690,9 @@ LIBGRPC++_UNSECURE_SRC = \
src/cpp/common/version_cc.cc \
src/cpp/server/async_generic_service.cc \
src/cpp/server/create_default_thread_pool.cc \
+ src/cpp/server/default_health_check_service.cc \
src/cpp/server/dynamic_thread_pool.cc \
+ src/cpp/server/health_check_service.cc \
src/cpp/server/server_builder.cc \
src/cpp/server/server_cc.cc \
src/cpp/server/server_context.cc \
diff --git a/build.yaml b/build.yaml
index 25dc9e0fcb..925c73b729 100644
--- a/build.yaml
+++ b/build.yaml
@@ -759,6 +759,7 @@ filegroups:
headers:
- src/cpp/client/create_channel_internal.h
- src/cpp/common/channel_filter.h
+ - src/cpp/server/default_health_check_service.h
- src/cpp/server/dynamic_thread_pool.h
- src/cpp/server/thread_pool_interface.h
- src/cpp/thread_manager/thread_manager.h
@@ -780,7 +781,9 @@ filegroups:
- src/cpp/common/version_cc.cc
- src/cpp/server/async_generic_service.cc
- src/cpp/server/create_default_thread_pool.cc
+ - src/cpp/server/default_health_check_service.cc
- src/cpp/server/dynamic_thread_pool.cc
+ - src/cpp/server/health_check_service.cc
- src/cpp/server/server_builder.cc
- src/cpp/server/server_cc.cc
- src/cpp/server/server_context.cc
diff --git a/include/grpc++/ext/health_check_service_server_builder_option.h b/include/grpc++/ext/health_check_service_server_builder_option.h
index fb5263d742..e00c4c3dd5 100644
--- a/include/grpc++/ext/health_check_service_server_builder_option.h
+++ b/include/grpc++/ext/health_check_service_server_builder_option.h
@@ -36,7 +36,7 @@
#include <memory>
-#include <grpc++/ext/health_check_service_interface.h>
+#include <grpc++/health_check_service_interface.h>
#include <grpc++/impl/server_builder_option.h>
#include <grpc++/support/config.h>
@@ -44,6 +44,7 @@ namespace grpc {
class HealthCheckServiceServerBuilderOption : public ServerBuilderOption {
public:
+ // Use nullptr to disable default service.
explicit HealthCheckServiceServerBuilderOption(
std::unique_ptr<HealthCheckServiceInterface> hc);
~HealthCheckServiceServerBuilderOption() {}
@@ -53,8 +54,6 @@ class HealthCheckServiceServerBuilderOption : public ServerBuilderOption {
std::unique_ptr<HealthCheckServiceInterface> hc_;
};
-void EnableDefaultHealthCheckService(bool enable);
-
} // namespace grpc
#endif // GRPCXX_EXT_HEALTH_CHECK_SERVICE_SERVER_BUILDER_OPTION_H
diff --git a/include/grpc++/health_check_service_interface.h b/include/grpc++/health_check_service_interface.h
new file mode 100644
index 0000000000..70153d65cb
--- /dev/null
+++ b/include/grpc++/health_check_service_interface.h
@@ -0,0 +1,63 @@
+/*
+ *
+ * Copyright 2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef GRPCXX_HEALTH_CHECK_SERVICE_INTERFACE_H
+#define GRPCXX_HEALTH_CHECK_SERVICE_INTERFACE_H
+
+#include <grpc++/support/config.h>
+
+namespace grpc {
+
+const char kDefaultHealthCheckServiceInterfaceArg[] =
+ "grpc.default_health_check_service_interface";
+
+class HealthCheckServiceInterface {
+ public:
+ virtual ~HealthCheckServiceInterface() {}
+ virtual void SetServingStatus(const grpc::string& service_name,
+ bool serving) = 0;
+ // Apply to all registered service names.
+ virtual void SetServingStatus(bool serving) = 0;
+};
+
+bool DefaultHealthCheckServiceEnabled();
+
+// Enable/disable the default health checking service. This applies to all C++
+// servers created afterwards. For each server, user can override the default
+// with a HealthCheckServiceServerBuilderOption.
+// NOT thread safe.
+void EnableDefaultHealthCheckService(bool enable);
+
+} // namespace grpc
+
+#endif // GRPCXX_HEALTH_CHECK_SERVICE_INTERFACE_H
diff --git a/include/grpc++/server.h b/include/grpc++/server.h
index fba9952e6e..511dc35564 100644
--- a/include/grpc++/server.h
+++ b/include/grpc++/server.h
@@ -97,6 +97,11 @@ class Server final : public ServerInterface, private GrpcLibraryCodegen {
// Returns a \em raw pointer to the underlying grpc_server instance.
grpc_server* c_server();
+ /// Returns the health check service.
+ HealthCheckServiceInterface* GetHealthCheckService() const {
+ return hc_.get();
+ }
+
private:
friend class AsyncGenericService;
friend class ServerBuilder;
@@ -214,6 +219,10 @@ class Server final : public ServerInterface, private GrpcLibraryCodegen {
grpc_server* server_;
std::unique_ptr<ServerInitializer> server_initializer_;
+
+ std::unique_ptr<HealthCheckServiceInterface> health_check_service_;
+ // User explicitly disabled health check service.
+ bool health_check_service_disabled_;
};
} // namespace grpc
diff --git a/src/cpp/ext/health_check_service_server_builder_option.cc b/src/cpp/ext/health_check_service_server_builder_option.cc
index dab5731e89..4afc82dc14 100644
--- a/src/cpp/ext/health_check_service_server_builder_option.cc
+++ b/src/cpp/ext/health_check_service_server_builder_option.cc
@@ -34,26 +34,16 @@
#include <grpc++/ext/health_check_service_server_builder_option.h>
namespace grpc {
-namespace {
-bool g_grpc_default_health_check_service_enabled = false;
-const char kDefaultHealthCheckServiceInterfaceArg[] = "grpc.default_health_check_service_interface";
-} // namesapce
HealthCheckServiceServerBuilderOption::HealthCheckServiceServerBuilderOption(
std::unique_ptr<HealthCheckServiceInterface> hc) : hc_(std::move(hc)) { }
HealthCheckServiceServerBuilderOption::UpdateArguments(ChannelArguments* args) override {
- args->SetPointer(kDefaultHealthCheckServiceInterfaceArg, hc_.release());
+ args->SetPointer(DefaultHealthCheckServiceInterfaceArg(), hc_.release());
}
void HealthCheckServiceServerBuilderOption::UpdatePlugins(std::vector<std::unique_ptr<ServerBuilderPlugin>>* plugins) override {
-
-}
-
-void EnableDefaultHealthCheckService(bool enable) {
- g_grpc_default_health_check_service_enabled = enable;
}
} // namespace grpc
-
diff --git a/src/cpp/server/default_health_check_service.cc b/src/cpp/server/default_health_check_service.cc
new file mode 100644
index 0000000000..eec7e2cd58
--- /dev/null
+++ b/src/cpp/server/default_health_check_service.cc
@@ -0,0 +1,67 @@
+/*
+ *
+ * Copyright 2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "src/cpp/server/default_health_check_service.h"
+
+namespace grpc {
+
+DefaultHealthCheckService::DefaultHealthCheckService() {
+ services_map_.insert("", true);
+}
+
+void DefaultHealthCheckService::SetServingStatus(
+ const grpc::string& service_name, bool serving) override {
+ std::lock_guard<std::mutex> lock(mu_);
+ services_map_[service_name] = serving;
+}
+
+void SetServingStatus(bool serving) override {
+ std::lock_guard<std::mutex> lock(mu_);
+ for (auto& iter = services_map_.begin(); iter != services_map_.end();
+ ++iter) {
+ iter->second = serving;
+ }
+}
+
+ServingStatus GetServingStatus(const grpc::string& service_name) const {
+ std::lock_guard<std::mutex> lock(mu_);
+ const auto& iter = services_map_.find(service_name);
+ if (iter == services_map_.end()) {
+ return NOT_FOUND;
+ }
+ return iter->second ? SERVING : NOT_SERVING;
+}
+
+} // namespace grpc
+
+#endif // GRPC_INTERNAL_CPP_SERVER_DEFAULT_HEALTH_CHECK_SERVICE_H
diff --git a/src/cpp/server/default_health_check_service.h b/src/cpp/server/default_health_check_service.h
new file mode 100644
index 0000000000..51afa6491e
--- /dev/null
+++ b/src/cpp/server/default_health_check_service.h
@@ -0,0 +1,59 @@
+/*
+ *
+ * Copyright 2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef GRPC_INTERNAL_CPP_SERVER_DEFAULT_HEALTH_CHECK_SERVICE_H
+#define GRPC_INTERNAL_CPP_SERVER_DEFAULT_HEALTH_CHECK_SERVICE_H
+
+#include <mutex>
+
+#include <grpc++/health_check_service_interface.h>
+
+namespace grpc {
+
+class DefaultHealthCheckService : public HealthCheckServiceInterface {
+ public:
+ DefaultHealthCheckService();
+ void SetServingStatus(const grpc::string& service_name,
+ bool serving) override;
+ void SetServingStatus(bool serving) override;
+ enum ServingStatus { NOT_FOUND, SERVING, NOT_SERVING };
+ ServingStatus GetServingStatus(const grpc::string& service_name) const;
+
+ private:
+ std::mutex mu_;
+ std::map<grpc::string, bool> services_map_;
+};
+
+} // namespace grpc
+
+#endif // GRPC_INTERNAL_CPP_SERVER_DEFAULT_HEALTH_CHECK_SERVICE_H
diff --git a/include/grpc++/ext/health_check_service_interface.h b/src/cpp/server/health_check_service.cc
index b9f4ebb87f..cca68c5549 100644
--- a/include/grpc++/ext/health_check_service_interface.h
+++ b/src/cpp/server/health_check_service.cc
@@ -31,22 +31,19 @@
*
*/
-#ifndef GRPCXX_EXT_HEALTH_CHECK_SERVICE_INTERFACE_H
-#define GRPCXX_EXT_HEALTH_CHECK_SERVICE_INTERFACE_H
-
-#include <grpc++/support/config.h>
+#include <grpc++/health_check_service_interface.h>
namespace grpc {
+namespace {
+bool g_grpc_default_health_check_service_enabled = false;
+} // namesapce
-class HealthCheckServiceInterface {
- public:
- virtual ~HealthCheckServiceInterface() { }
- virtual void SetServingStatus(const grpc::string& service_name, bool serving) = 0;
- // Apply to all registered service names.
- virtual void SetServingStatus(bool serving) = 0;
-};
+bool DefaultHealthCheckServiceEnabled() {
+ return g_grpc_default_health_check_service_enabled;
+}
+void EnableDefaultHealthCheckService(bool enable) {
+ g_grpc_default_health_check_service_enabled = enable;
+}
} // namespace grpc
-
-#endif // GRPCXX_EXT_HEALTH_CHECK_SERVICE_INTERFACE_H
diff --git a/src/cpp/server/server_cc.cc b/src/cpp/server/server_cc.cc
index 817d85a81c..037da2b301 100644
--- a/src/cpp/server/server_cc.cc
+++ b/src/cpp/server/server_cc.cc
@@ -36,6 +36,7 @@
#include <utility>
#include <grpc++/completion_queue.h>
+#include <grpc++/ext/g.h>
#include <grpc++/generic/async_generic_service.h>
#include <grpc++/impl/codegen/completion_queue_tag.h>
#include <grpc++/impl/grpc_library.h>
@@ -342,6 +343,7 @@ class Server::SyncRequestThreadManager : public ThreadManager {
int cq_timeout_msec_;
std::vector<std::unique_ptr<SyncRequest>> sync_requests_;
std::unique_ptr<RpcServiceMethod> unknown_method_;
+ std::unique_ptr<RpcServiceMethod> health_check_;
std::shared_ptr<Server::GlobalCallbacks> global_callbacks_;
};
@@ -358,7 +360,8 @@ Server::Server(
shutdown_notified_(false),
has_generic_service_(false),
server_(nullptr),
- server_initializer_(new ServerInitializer(this)) {
+ server_initializer_(new ServerInitializer(this)),
+ health_check_service_disabled_(false) {
g_gli_initializer.summon();
gpr_once_init(&g_once_init_callbacks, InitGlobalCallbacks);
global_callbacks_ = g_callbacks;
@@ -374,6 +377,18 @@ Server::Server(
grpc_channel_args channel_args;
args->SetChannelArgs(&channel_args);
+ for (size_t i = 0; i < channel_args.num_args; i++) {
+ if (0 == strcmp(channel_args.args[i].key,
+ kDefaultHealthCheckServiceInterfaceArg)) {
+ if (channel_args.args[i].value == nullptr) {
+ health_check_service_disabled_ = true;
+ } else {
+ health_check_service_.reset(channel_args.args[i].value);
+ }
+ break;
+ }
+ }
+
server_ = grpc_server_create(&channel_args, nullptr);
}
@@ -481,6 +496,22 @@ bool Server::Start(ServerCompletionQueue** cqs, size_t num_cqs) {
started_ = true;
grpc_server_start(server_);
+ // Only create default health check service when user did not provide an
+ // explicit one.
+ if (health_check_service_ == nullptr && !health_check_service_disabled_ &&
+ EnableDefaultHealthCheckService()) {
+ health_check_service_.reset(CreateDefaultHealthCheckService());
+ for (auto it = sync_req_mgrs_.begin(); it != sync_req_mgrs_.end(); it++) {
+ (*it)->AddHealthCheckSyncMethod();
+ }
+
+ for (size_t i = 0; i < num_cqs; i++) {
+ if (cqs[i]->IsFrequentlyPolled()) {
+ // new UnimplementedAsyncRequest(this, cqs[i]);
+ }
+ }
+ }
+
if (!has_generic_service_) {
for (auto it = sync_req_mgrs_.begin(); it != sync_req_mgrs_.end(); it++) {
(*it)->AddUnknownSyncMethod();
diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal
index ac20f0fc02..aa79aedeb9 100644
--- a/tools/doxygen/Doxyfile.c++.internal
+++ b/tools/doxygen/Doxyfile.c++.internal
@@ -855,6 +855,7 @@ src/cpp/common/secure_auth_context.h \
src/cpp/server/secure_server_credentials.h \
src/cpp/client/create_channel_internal.h \
src/cpp/common/channel_filter.h \
+src/cpp/server/default_health_check_service.h \
src/cpp/server/dynamic_thread_pool.h \
src/cpp/server/thread_pool_interface.h \
src/cpp/thread_manager/thread_manager.h \
@@ -883,7 +884,9 @@ src/cpp/common/rpc_method.cc \
src/cpp/common/version_cc.cc \
src/cpp/server/async_generic_service.cc \
src/cpp/server/create_default_thread_pool.cc \
+src/cpp/server/default_health_check_service.cc \
src/cpp/server/dynamic_thread_pool.cc \
+src/cpp/server/health_check_service.cc \
src/cpp/server/server_builder.cc \
src/cpp/server/server_cc.cc \
src/cpp/server/server_context.cc \
diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json
index cb92999b26..860a151f48 100644
--- a/tools/run_tests/generated/sources_and_headers.json
+++ b/tools/run_tests/generated/sources_and_headers.json
@@ -7658,6 +7658,7 @@
"include/grpc++/support/time.h",
"src/cpp/client/create_channel_internal.h",
"src/cpp/common/channel_filter.h",
+ "src/cpp/server/default_health_check_service.h",
"src/cpp/server/dynamic_thread_pool.h",
"src/cpp/server/thread_pool_interface.h",
"src/cpp/thread_manager/thread_manager.h"
@@ -7729,8 +7730,11 @@
"src/cpp/common/version_cc.cc",
"src/cpp/server/async_generic_service.cc",
"src/cpp/server/create_default_thread_pool.cc",
+ "src/cpp/server/default_health_check_service.cc",
+ "src/cpp/server/default_health_check_service.h",
"src/cpp/server/dynamic_thread_pool.cc",
"src/cpp/server/dynamic_thread_pool.h",
+ "src/cpp/server/health_check_service.cc",
"src/cpp/server/server_builder.cc",
"src/cpp/server/server_cc.cc",
"src/cpp/server/server_context.cc",
diff --git a/vsprojects/vcxproj/grpc++/grpc++.vcxproj b/vsprojects/vcxproj/grpc++/grpc++.vcxproj
index 468accbd23..a57ed0e2e5 100644
--- a/vsprojects/vcxproj/grpc++/grpc++.vcxproj
+++ b/vsprojects/vcxproj/grpc++/grpc++.vcxproj
@@ -355,6 +355,7 @@
<ClInclude Include="$(SolutionDir)\..\src\cpp\server\secure_server_credentials.h" />
<ClInclude Include="$(SolutionDir)\..\src\cpp\client\create_channel_internal.h" />
<ClInclude Include="$(SolutionDir)\..\src\cpp\common\channel_filter.h" />
+ <ClInclude Include="$(SolutionDir)\..\src\cpp\server\default_health_check_service.h" />
<ClInclude Include="$(SolutionDir)\..\src\cpp\server\dynamic_thread_pool.h" />
<ClInclude Include="$(SolutionDir)\..\src\cpp\server\thread_pool_interface.h" />
<ClInclude Include="$(SolutionDir)\..\src\cpp\thread_manager\thread_manager.h" />
@@ -410,8 +411,12 @@
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\cpp\server\create_default_thread_pool.cc">
</ClCompile>
+ <ClCompile Include="$(SolutionDir)\..\src\cpp\server\default_health_check_service.cc">
+ </ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\cpp\server\dynamic_thread_pool.cc">
</ClCompile>
+ <ClCompile Include="$(SolutionDir)\..\src\cpp\server\health_check_service.cc">
+ </ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\cpp\server\server_builder.cc">
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\cpp\server\server_cc.cc">
diff --git a/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters b/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters
index d21b97b8df..e455636abe 100644
--- a/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters
+++ b/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters
@@ -76,9 +76,15 @@
<ClCompile Include="$(SolutionDir)\..\src\cpp\server\create_default_thread_pool.cc">
<Filter>src\cpp\server</Filter>
</ClCompile>
+ <ClCompile Include="$(SolutionDir)\..\src\cpp\server\default_health_check_service.cc">
+ <Filter>src\cpp\server</Filter>
+ </ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\cpp\server\dynamic_thread_pool.cc">
<Filter>src\cpp\server</Filter>
</ClCompile>
+ <ClCompile Include="$(SolutionDir)\..\src\cpp\server\health_check_service.cc">
+ <Filter>src\cpp\server</Filter>
+ </ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\cpp\server\server_builder.cc">
<Filter>src\cpp\server</Filter>
</ClCompile>
@@ -404,6 +410,9 @@
<ClInclude Include="$(SolutionDir)\..\src\cpp\common\channel_filter.h">
<Filter>src\cpp\common</Filter>
</ClInclude>
+ <ClInclude Include="$(SolutionDir)\..\src\cpp\server\default_health_check_service.h">
+ <Filter>src\cpp\server</Filter>
+ </ClInclude>
<ClInclude Include="$(SolutionDir)\..\src\cpp\server\dynamic_thread_pool.h">
<Filter>src\cpp\server</Filter>
</ClInclude>
diff --git a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj
index f0e3f3a23e..10c9be3339 100644
--- a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj
+++ b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj
@@ -351,6 +351,7 @@
<ItemGroup>
<ClInclude Include="$(SolutionDir)\..\src\cpp\client\create_channel_internal.h" />
<ClInclude Include="$(SolutionDir)\..\src\cpp\common\channel_filter.h" />
+ <ClInclude Include="$(SolutionDir)\..\src\cpp\server\default_health_check_service.h" />
<ClInclude Include="$(SolutionDir)\..\src\cpp\server\dynamic_thread_pool.h" />
<ClInclude Include="$(SolutionDir)\..\src\cpp\server\thread_pool_interface.h" />
<ClInclude Include="$(SolutionDir)\..\src\cpp\thread_manager\thread_manager.h" />
@@ -396,8 +397,12 @@
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\cpp\server\create_default_thread_pool.cc">
</ClCompile>
+ <ClCompile Include="$(SolutionDir)\..\src\cpp\server\default_health_check_service.cc">
+ </ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\cpp\server\dynamic_thread_pool.cc">
</ClCompile>
+ <ClCompile Include="$(SolutionDir)\..\src\cpp\server\health_check_service.cc">
+ </ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\cpp\server\server_builder.cc">
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\cpp\server\server_cc.cc">
diff --git a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters
index 6076dbc693..0b65ff3fe8 100644
--- a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters
+++ b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters
@@ -61,9 +61,15 @@
<ClCompile Include="$(SolutionDir)\..\src\cpp\server\create_default_thread_pool.cc">
<Filter>src\cpp\server</Filter>
</ClCompile>
+ <ClCompile Include="$(SolutionDir)\..\src\cpp\server\default_health_check_service.cc">
+ <Filter>src\cpp\server</Filter>
+ </ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\cpp\server\dynamic_thread_pool.cc">
<Filter>src\cpp\server</Filter>
</ClCompile>
+ <ClCompile Include="$(SolutionDir)\..\src\cpp\server\health_check_service.cc">
+ <Filter>src\cpp\server</Filter>
+ </ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\cpp\server\server_builder.cc">
<Filter>src\cpp\server</Filter>
</ClCompile>
@@ -377,6 +383,9 @@
<ClInclude Include="$(SolutionDir)\..\src\cpp\common\channel_filter.h">
<Filter>src\cpp\common</Filter>
</ClInclude>
+ <ClInclude Include="$(SolutionDir)\..\src\cpp\server\default_health_check_service.h">
+ <Filter>src\cpp\server</Filter>
+ </ClInclude>
<ClInclude Include="$(SolutionDir)\..\src\cpp\server\dynamic_thread_pool.h">
<Filter>src\cpp\server</Filter>
</ClInclude>