Go to the documentation of this file.
19 #ifndef GRPCPP_SERVER_H
20 #define GRPCPP_SERVER_H
45 class AsyncGenericService;
47 class ServerInitializer;
50 class ExternalConnectionAcceptorImpl;
59 ~Server() ABSL_LOCKS_EXCLUDED(mu_)
override;
65 void Wait() ABSL_LOCKS_EXCLUDED(mu_)
override;
101 return health_check_service_.get();
119 std::unique_ptr<experimental::ClientInterceptorFactoryInterface>>
120 interceptor_creators);
175 std::shared_ptr<std::vector<std::unique_ptr<ServerCompletionQueue>>>
177 int min_pollers,
int max_pollers,
int sync_cq_timeout_msec,
178 std::vector<std::shared_ptr<internal::ExternalConnectionAcceptorImpl>>
183 std::unique_ptr<experimental::ServerInterceptorFactoryInterface>>
184 interceptor_creators = std::vector<std::unique_ptr<
200 std::unique_ptr<HealthCheckServiceInterface> service) {
201 health_check_service_ = std::move(service);
208 return health_check_service_disabled_;
212 std::vector<std::unique_ptr<experimental::ServerInterceptorFactoryInterface>>*
213 interceptor_creators()
override {
214 return &interceptor_creators_;
222 class CallbackRequestBase;
223 template <
class ServerContextType>
224 class CallbackRequest;
225 class UnimplementedAsyncRequest;
226 class UnimplementedAsyncResponse;
232 class SyncRequestThreadManager;
243 void RegisterContextAllocator(
252 ABSL_LOCKS_EXCLUDED(mu_)
override;
254 int max_receive_message_size()
const override {
255 return max_receive_message_size_;
258 bool call_metric_recording_enabled()
const override {
259 return call_metric_recording_enabled_;
262 experimental::ServerMetricRecorder* server_metric_recorder()
const override {
263 return server_metric_recorder_;
266 CompletionQueue* CallbackCQ() ABSL_LOCKS_EXCLUDED(mu_) override;
274 void UnrefWithPossibleNotify() ABSL_LOCKS_EXCLUDED(mu_);
275 void UnrefAndWaitLocked() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_);
277 std::vector<
std::shared_ptr<internal::ExternalConnectionAcceptorImpl>>
286 interceptor_creators_;
288 int max_receive_message_size_;
293 std::shared_ptr<
std::vector<
std::unique_ptr<ServerCompletionQueue>>>
298 std::vector<
std::unique_ptr<SyncRequestThreadManager>> sync_req_mgrs_;
303 bool shutdown_ ABSL_GUARDED_BY(mu_);
304 bool shutdown_notified_
305 ABSL_GUARDED_BY(mu_);
306 internal::CondVar shutdown_done_cv_;
307 bool shutdown_done_ ABSL_GUARDED_BY(mu_) = false;
308 std::atomic_int shutdown_refs_outstanding_{1};
310 internal::CondVar shutdown_cv_;
312 std::shared_ptr<GlobalCallbacks> global_callbacks_;
314 std::vector<std::string> services_;
315 bool has_async_generic_service_ =
false;
316 bool has_callback_generic_service_ =
false;
317 bool has_callback_methods_ =
false;
322 std::unique_ptr<ServerInitializer> server_initializer_;
324 std::unique_ptr<ContextAllocator> context_allocator_;
326 std::unique_ptr<HealthCheckServiceInterface> health_check_service_;
327 bool health_check_service_disabled_;
331 std::unique_ptr<CallbackGenericService> unimplemented_service_;
334 std::unique_ptr<internal::MethodHandler> resource_exhausted_handler_;
337 std::unique_ptr<internal::MethodHandler> generic_handler_;
343 std::atomic<CompletionQueue*> callback_cq_{
nullptr};
348 std::vector<CompletionQueue*> cq_list_;
351 bool call_metric_recording_enabled_ =
false;
354 experimental::ServerMetricRecorder* server_metric_recorder_ =
nullptr;
359 #endif // GRPCPP_SERVER_H
std::shared_ptr< Channel > InProcessChannel(const ChannelArguments &args)
Establish a channel for in-process communication.
Records server wide metrics to be reported to the client.
Definition: server_metric_recorder.h:42
A ServerContext or CallbackServerContext allows the code implementing a service handler to:
Definition: server_context.h:578
Represents a gRPC server.
Definition: server.h:57
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:400
~Server() ABSL_LOCKS_EXCLUDED(mu_) override
bool RegisterService(const std::string *addr, Service *service) override
Register a service.
bool health_check_service_disabled() const
NOTE: This method is not part of the public API for this class.
Definition: server.h:207
ContextAllocator * context_allocator()
Definition: server.h:204
Definition: server_initializer.h:31
virtual void PostSynchronousRequest(ServerContext *context)=0
Called after application callback for each synchronous server request.
The gRPC server uses this interface to expose the health checking service without depending on protob...
Definition: health_check_service_interface.h:31
Wrapper around grpc_server_credentials, a way to authenticate a server.
Definition: server_credentials.h:69
Straightforward wrapping of the C call object.
Definition: call.h:36
experimental_type(Server *server)
Definition: server.h:112
virtual void PreSynchronousRequest(ServerContext *context)=0
Called before application callback for each synchronous server request.
void Start(ServerCompletionQueue **cqs, size_t num_cqs) override
Start the server.
Descriptor of an RPC service and its various RPC methods.
Definition: service_type.h:58
struct grpc_server_config_fetcher grpc_server_config_fetcher
Definition: grpc.h:448
virtual void AddPort(Server *, const std::string &, ServerCredentials *, int)
Called after a server port is added.
Definition: server.h:85
void Wait() ABSL_LOCKS_EXCLUDED(mu_) override
Block until the server shuts down.
virtual ~GlobalCallbacks()
Definition: server.h:75
Options for channel creation.
Definition: channel_arguments.h:39
friend class ServerInitializer
Definition: server.h:219
int AddListeningPort(const std::string &addr, ServerCredentials *creds) override
Try binding the server to the given addr endpoint (port, and optionally including IP address to bind ...
An abstract collection of call ops, used to generate the grpc_call_op structure to pass down to the l...
Definition: call_op_set_interface.h:36
struct grpc_server grpc_server
A server listens to some port and responds to request calls.
Definition: grpc_types.h:64
grpc_server * server() override
Definition: server.h:196
virtual void UpdateArguments(ChannelArguments *)
Called before server is created.
Definition: server.h:77
virtual void PreServerStart(Server *)
Called before server is started.
Definition: server.h:83
Definition: async_generic_service.h:66
Classes that require gRPC to be initialized should inherit from this class.
Definition: grpc_library.h:32
NOTE: class experimental_type is not part of the public API of this class.
Definition: server.h:110
Definition: server_interceptor.h:46
HealthCheckServiceInterface * GetHealthCheckService() const
Returns the health check service.
Definition: server.h:100
A CallbackServerContext allows users to use the contents of the CallbackServerContext or GenericCallb...
Definition: server_context.h:662
std::shared_ptr< Channel > InProcessChannelWithInterceptors(const ChannelArguments &args, std::vector< std::unique_ptr< experimental::ClientInterceptorFactoryInterface >> interceptor_creators)
Establish a channel for in-process communication with client interceptors.
A specific type of completion queue used by the processing of notifications by servers.
Definition: completion_queue.h:427
Definition: async_unary_call.h:407
static void SetGlobalCallbacks(GlobalCallbacks *callbacks)
Set the global callback object.
grpc_server * c_server()
Returns a raw pointer to the underlying grpc_server instance.
void set_health_check_service(std::unique_ptr< HealthCheckServiceInterface > service)
NOTE: This method is not part of the public API for this class.
Definition: server.h:199
A builder class for the creation and startup of grpc::Server instances.
Definition: server_builder.h:88
Definition: server_interface.h:61
Analogous to struct timespec.
Definition: time.h:48
Global callbacks are a set of hooks that are called when server events occur.
Definition: server.h:73
Server(ChannelArguments *args, std::shared_ptr< std::vector< std::unique_ptr< ServerCompletionQueue >>> sync_server_cqs, int min_pollers, int max_pollers, int sync_cq_timeout_msec, std::vector< std::shared_ptr< internal::ExternalConnectionAcceptorImpl >> acceptors, grpc_server_config_fetcher *server_config_fetcher=nullptr, grpc_resource_quota *server_rq=nullptr, std::vector< std::unique_ptr< experimental::ServerInterceptorFactoryInterface >> interceptor_creators=std::vector< std::unique_ptr< experimental::ServerInterceptorFactoryInterface >>(), experimental::ServerMetricRecorder *server_metric_recorder=nullptr)
NOTE: This is NOT a public API.
CallbackGenericService is the base class for generic services implemented using the callback API and ...
Definition: callback_generic_service.h:51
experimental_type experimental()
NOTE: The function experimental() is not stable public API.
Definition: server.h:129