aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp/server/server_builder.cc
diff options
context:
space:
mode:
authorGravatar Sree Kuchibhotla <sreek@google.com>2016-05-16 11:06:30 -0700
committerGravatar Sree Kuchibhotla <sreek@google.com>2016-05-16 11:06:30 -0700
commit4790263c5f20865ed4279f479b184205dd7209b4 (patch)
tree2ee321081bdad50b32587fe4b8215e5d01d24042 /src/cpp/server/server_builder.cc
parent088891119f17b827b4f45f09e39411f007618ddf (diff)
parent1ba1bba66a18b6b7986a1cfa52c6f1ac4a14a029 (diff)
Merge branch 'master' into server_channel_affinity
Diffstat (limited to 'src/cpp/server/server_builder.cc')
-rw-r--r--src/cpp/server/server_builder.cc44
1 files changed, 41 insertions, 3 deletions
diff --git a/src/cpp/server/server_builder.cc b/src/cpp/server/server_builder.cc
index 9cd7cb2da3..a2d90c2974 100644
--- a/src/cpp/server/server_builder.cc
+++ b/src/cpp/server/server_builder.cc
@@ -41,9 +41,23 @@
namespace grpc {
+static std::vector<std::unique_ptr<ServerBuilderPlugin> (*)()>*
+ g_plugin_factory_list;
+static gpr_once once_init_plugin_list = GPR_ONCE_INIT;
+
+static void do_plugin_list_init(void) {
+ g_plugin_factory_list =
+ new std::vector<std::unique_ptr<ServerBuilderPlugin> (*)()>();
+}
+
ServerBuilder::ServerBuilder()
: max_message_size_(-1), generic_service_(nullptr) {
grpc_compression_options_init(&compression_options_);
+ gpr_once_init(&once_init_plugin_list, do_plugin_list_init);
+ for (auto factory : (*g_plugin_factory_list)) {
+ std::unique_ptr<ServerBuilderPlugin> plugin = factory();
+ plugins_[plugin->name()] = std::move(plugin);
+ }
}
std::unique_ptr<ServerCompletionQueue> ServerBuilder::AddCompletionQueue(
@@ -100,18 +114,30 @@ std::unique_ptr<Server> ServerBuilder::BuildAndStart() {
ChannelArguments args;
for (auto option = options_.begin(); option != options_.end(); ++option) {
(*option)->UpdateArguments(&args);
+ (*option)->UpdatePlugins(&plugins_);
+ }
+ if (thread_pool == nullptr) {
+ for (auto plugin = plugins_.begin(); plugin != plugins_.end(); plugin++) {
+ if ((*plugin).second->has_sync_methods()) {
+ thread_pool.reset(CreateDefaultThreadPool());
+ break;
+ }
+ }
}
if (max_message_size_ > 0) {
args.SetInt(GRPC_ARG_MAX_MESSAGE_LENGTH, max_message_size_);
}
- args.SetInt(GRPC_COMPRESSION_ALGORITHM_STATE_ARG,
+ args.SetInt(GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET,
compression_options_.enabled_algorithms_bitset);
std::unique_ptr<Server> server(
new Server(thread_pool.release(), true, max_message_size_, &args));
+ ServerInitializer* initializer = server->initializer();
+
// If the server has atleast one sync methods, we know that this is a Sync
- // server or a Hybrid server and the completion queue (server->cq_) would be
- // frequently polled.
+ // server or a Hybrid server. This means that the completion queue on the
+ // Server object (i.e server->cq_) will be frequently polled (which is why
+ // we initialize num_frequently_pollsed_cqs to 1 here)
int num_frequently_polled_cqs = has_sync_methods ? 1 : 0;
for (auto cq = cqs_.begin(); cq != cqs_.end(); ++cq) {
@@ -141,6 +167,9 @@ std::unique_ptr<Server> ServerBuilder::BuildAndStart() {
return nullptr;
}
}
+ for (auto plugin = plugins_.begin(); plugin != plugins_.end(); plugin++) {
+ (*plugin).second->InitServer(initializer);
+ }
if (generic_service_) {
server->RegisterAsyncGenericService(generic_service_);
} else {
@@ -164,7 +193,16 @@ std::unique_ptr<Server> ServerBuilder::BuildAndStart() {
if (!server->Start(cqs_data, cqs_.size())) {
return nullptr;
}
+ for (auto plugin = plugins_.begin(); plugin != plugins_.end(); plugin++) {
+ (*plugin).second->Finish(initializer);
+ }
return server;
}
+void ServerBuilder::InternalAddPluginFactory(
+ std::unique_ptr<ServerBuilderPlugin> (*CreatePlugin)()) {
+ gpr_once_init(&once_init_plugin_list, do_plugin_list_init);
+ (*g_plugin_factory_list).push_back(CreatePlugin);
+}
+
} // namespace grpc