Go to the documentation of this file.
19 #ifndef GRPCPP_SERVER_BUILDER_H
20 #define GRPCPP_SERVER_BUILDER_H
47 class CompletionQueue;
49 class ServerCompletionQueue;
50 class AsyncGenericService;
52 class ServerCredentials;
55 class ServerBuilderPluginTest;
59 class ExternalConnectionAcceptorImpl;
62 class CallbackGenericService;
64 namespace experimental {
130 const std::string& addr_uri,
131 std::shared_ptr<grpc::ServerCredentials> creds,
132 int* selected_port =
nullptr);
165 bool is_frequently_polled =
true);
190 max_receive_message_size_ = max_receive_message_size;
197 max_send_message_size_ = max_send_message_size;
228 std::shared_ptr<grpc_event_engine::experimental::EventEngine>
253 std::unique_ptr<grpc::ServerBuilderPlugin> (*CreatePlugin)());
268 std::vector<std::unique_ptr<
270 interceptor_creators) {
271 builder_->interceptor_creators_ = std::move(interceptor_creators);
282 std::unique_ptr<grpc::experimental::ExternalConnectionAcceptor>
284 std::shared_ptr<ServerCredentials> creds);
289 std::shared_ptr<experimental::AuthorizationPolicyProviderInterface>
311 std::shared_ptr<grpc::ServerCredentials> creds,
312 std::unique_ptr<grpc::experimental::PassiveListener>& passive_listener);
321 std::unique_ptr<grpc::ContextAllocator> context_allocator);
339 std::shared_ptr<ServerCredentials>
creds;
354 std::vector<Port>
ports() {
return ports_; }
358 std::vector<NamedService*> service_refs;
359 service_refs.reserve(services_.size());
360 for (
auto& ptr : services_) {
361 service_refs.push_back(ptr.get());
367 std::vector<grpc::ServerBuilderOption*>
options() {
368 std::vector<grpc::ServerBuilderOption*> option_refs;
369 option_refs.reserve(options_.size());
370 for (
auto& ptr : options_) {
371 option_refs.push_back(ptr.get());
378 server_config_fetcher_ = server_config_fetcher;
387 struct UnstartedPassiveListener {
388 std::weak_ptr<grpc_core::experimental::PassiveListenerImpl>
390 std::shared_ptr<grpc::ServerCredentials> credentials;
391 UnstartedPassiveListener(
392 std::weak_ptr<grpc_core::experimental::PassiveListenerImpl> listener,
393 std::shared_ptr<grpc::ServerCredentials> creds)
394 : passive_listener(
std::move(listener)),
395 credentials(
std::move(creds)) {}
398 struct SyncServerSettings {
400 : num_cqs(1), min_pollers(1), max_pollers(2), cq_timeout_msec(10000) {}
417 int max_receive_message_size_;
418 int max_send_message_size_;
419 std::vector<std::unique_ptr<grpc::ServerBuilderOption>> options_;
420 std::vector<std::unique_ptr<NamedService>> services_;
421 std::vector<Port> ports_;
422 std::vector<UnstartedPassiveListener> unstarted_passive_listeners_;
424 SyncServerSettings sync_server_settings_;
427 std::vector<grpc::ServerCompletionQueue*> cqs_;
429 std::shared_ptr<grpc::ServerCredentials> creds_;
430 std::vector<std::unique_ptr<grpc::ServerBuilderPlugin>> plugins_;
433 std::unique_ptr<ContextAllocator> context_allocator_;
435 std::shared_ptr<grpc_event_engine::experimental::EventEngine> event_engine_ =
441 } maybe_default_compression_level_;
445 } maybe_default_compression_algorithm_;
446 uint32_t enabled_compression_algorithms_bitset_;
448 std::unique_ptr<grpc::experimental::ServerInterceptorFactoryInterface>>
449 interceptor_creators_;
450 std::vector<std::shared_ptr<grpc::internal::ExternalConnectionAcceptorImpl>>
453 std::shared_ptr<experimental::AuthorizationPolicyProviderInterface>
454 authorization_provider_;
460 #endif // GRPCPP_SERVER_BUILDER_H
grpc_compression_level level
Definition: server_builder.h:440
Definition: server_builder.h:345
virtual std::unique_ptr< grpc::Server > BuildAndStart()
Return a running server which is ready for processing calls.
ServerBuilder & SetEventEngine(std::shared_ptr< grpc_event_engine::experimental::EventEngine > event_engine)
grpc_compression_algorithm algorithm
Definition: server_builder.h:444
std::unique_ptr< ServerBuilderOption > MakeChannelArgumentOption(const std::string &name, const std::string &value)
Records server wide metrics to be reported to the client.
Definition: server_metric_recorder.h:42
ServerBuilder & SetDefaultCompressionAlgorithm(grpc_compression_algorithm algorithm)
The default compression algorithm to use for all channel calls in the absence of a call-specific leve...
ServerBuilder & RegisterCallbackGenericService(grpc::CallbackGenericService *service)
Register a generic service that uses the callback API.
ServerBuilder & EnableWorkaround(grpc_workaround_list id)
Enable a server workaround.
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
struct grpc_resource_quota grpc_resource_quota
Definition: grpc_types.h:399
std::vector< Port > ports()
Experimental, to be deprecated.
Definition: server_builder.h:354
NamedService(const std::string &h, grpc::Service *s)
Definition: server_builder.h:347
grpc_compression_algorithm
The various compression algorithms supported by gRPC (not sorted by compression level)
Definition: compression_types.h:61
std::unique_ptr< grpc::experimental::ExternalConnectionAcceptor > AddExternalConnectionAcceptor(ExternalConnectionType type, std::shared_ptr< ServerCredentials > creds)
Register an acceptor to handle the externally accepted connection in grpc server.
std::string addr
Definition: server_builder.h:338
void set_fetcher(grpc_server_config_fetcher *server_config_fetcher)
Experimental API, subject to change.
Definition: server_builder.h:377
Descriptor of an RPC service and its various RPC methods.
Definition: service_type.h:57
static void InternalAddPluginFactory(std::unique_ptr< grpc::ServerBuilderPlugin >(*CreatePlugin)())
For internal use only: Register a ServerBuilderPlugin factory function.
Experimental, to be deprecated.
Definition: server_builder.h:337
virtual ChannelArguments BuildChannelArgs()
Experimental API, subject to change.
struct grpc_server_config_fetcher grpc_server_config_fetcher
Definition: grpc.h:447
int * selected_port
Definition: server_builder.h:340
friend class grpc::testing::ServerBuilderPluginTest
Definition: server_builder.h:385
Options for channel creation.
Definition: channel_arguments.h:39
@ NUM_CQS
Number of completion queues.
Definition: server_builder.h:235
ExternalConnectionType
Definition: server_builder.h:274
ByteBuffer read_buffer
Definition: server_builder.h:74
Definition: server_builder.h:71
int fd
Definition: server_builder.h:73
@ MAX_POLLERS
Maximum number of polling threads.
Definition: server_builder.h:237
ServerBuilder & SetDefaultCompressionLevel(grpc_compression_level level)
The default compression level to use for all channel calls in the absence of a call-specific level.
void EnableCallMetricRecording(experimental::ServerMetricRecorder *server_metric_recorder=nullptr)
Enables per-call load reporting.
A sequence of bytes.
Definition: byte_buffer.h:59
experimental_type(ServerBuilder *builder)
Definition: server_builder.h:265
ResourceQuota represents a bound on memory and thread usage by the gRPC library.
Definition: resource_quota.h:34
std::unique_ptr< std::string > HostString
Experimental, to be deprecated.
Definition: server_builder.h:344
ServerBuilder & RegisterAsyncGenericService(grpc::AsyncGenericService *service)
Register a generic service.
NOTE: class experimental_type is not part of the public API of this class.
Definition: server_builder.h:263
Definition: async_generic_service.h:66
Definition: server_builder.h:69
@ CQ_TIMEOUT_MSEC
Completion queue timeout in milliseconds.
Definition: server_builder.h:238
ServerBuilder & SetMaxMessageSize(int max_message_size)
Definition: server_builder.h:202
ServerBuilder & SetSyncServerOption(SyncServerOption option, int value)
Only useful if this is a Synchronous server.
ServerBuilder & SetContextAllocator(std::unique_ptr< grpc::ContextAllocator > context_allocator)
Set the allocator for creating and releasing callback server context.
ServerBuilder & AddPassiveListener(std::shared_ptr< grpc::ServerCredentials > creds, std::unique_ptr< grpc::experimental::PassiveListener > &passive_listener)
PassiveListener lets applications provide pre-established connections to gRPC Servers.
ServerBuilder & SetCompressionAlgorithmSupportStatus(grpc_compression_algorithm algorithm, bool enabled)
Set the support status for compression algorithms.
SyncServerOption
Options for synchronous servers.
Definition: server_builder.h:234
std::vector< NamedService * > services()
Experimental, to be deprecated.
Definition: server_builder.h:357
Definition: server_interceptor.h:45
grpc::Service * service
Definition: server_builder.h:350
bool is_set
Definition: server_builder.h:439
std::unique_ptr< grpc::ServerCompletionQueue > AddCompletionQueue(bool is_frequently_polled=true)
Add a completion queue for handling asynchronous services.
std::shared_ptr< ServerCredentials > creds
Definition: server_builder.h:339
void SetAuthorizationPolicyProvider(std::shared_ptr< experimental::AuthorizationPolicyProviderInterface > provider)
Sets server authorization policy provider in GRPC_ARG_AUTHORIZATION_POLICY_PROVIDER channel argument.
HostString host
Definition: server_builder.h:349
grpc_workaround_list
Definition: workaround_list.h:26
grpc_compression_level
Compression levels allow a party with knowledge of its peer's accepted encodings to request compressi...
Definition: compression_types.h:73
Definition: async_unary_call.h:410
virtual ~ExternalConnectionAcceptor()
Definition: server_builder.h:76
ServerBuilder & SetResourceQuota(const grpc::ResourceQuota &resource_quota)
Set the attached buffer pool for this server.
void SetInterceptorCreators(std::vector< std::unique_ptr< grpc::experimental::ServerInterceptorFactoryInterface >> interceptor_creators)
Definition: server_builder.h:267
NamedService(grpc::Service *s)
Definition: server_builder.h:346
ServerBuilder & AddListeningPort(const std::string &addr_uri, std::shared_ptr< grpc::ServerCredentials > creds, int *selected_port=nullptr)
Enlists an endpoint addr (port with an optional IP address) to bind the grpc::Server object to be cre...
virtual void HandleNewConnection(NewConnectionParameters *p)=0
int listener_fd
Definition: server_builder.h:72
experimental_type experimental()
NOTE: The function experimental() is not stable public API.
Definition: server_builder.h:333
A builder class for the creation and startup of grpc::Server instances.
Definition: server_builder.h:88
ServerBuilder & SetOption(std::unique_ptr< grpc::ServerBuilderOption > option)
ServerBuilder & SetMaxReceiveMessageSize(int max_receive_message_size)
Set max receive message size in bytes.
Definition: server_builder.h:189
std::vector< grpc::ServerBuilderOption * > options()
Experimental, to be deprecated.
Definition: server_builder.h:367
ServerBuilder & AddChannelArgument(const std::string &arg, const T &value)
Add a channel argument (an escape hatch to tuning core library parameters directly)
Definition: server_builder.h:247
@ MIN_POLLERS
Minimum number of polling threads.
Definition: server_builder.h:236
ServerBuilder & SetMaxSendMessageSize(int max_send_message_size)
Set max send message size in bytes.
Definition: server_builder.h:196
ServerBuilder & RegisterService(grpc::Service *service)
Register a service.
CallbackGenericService is the base class for generic services implemented using the callback API and ...
Definition: callback_generic_service.h:51