userver: userver/server/component.hpp Source File
Loading...
Searching...
No Matches
component.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/server/component.hpp
4/// @brief @copybrief components::Server
5
6#include <memory>
7
8#include <userver/engine/task/task_processor_fwd.hpp>
9#include <userver/server/component_base.hpp>
10#include <userver/server/server.hpp>
11#include <userver/utils/statistics/fwd.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
15namespace components {
16
17/// @ingroup userver_components
18///
19/// @brief Component that listens for incoming requests, manages
20/// incoming connections and passes the requests to the appropriate handler.
21///
22/// Starts listening and accepting connections only after **all** the
23/// components are loaded.
24///
25/// All the classes inherited from server::handlers::HttpHandlerBase and
26/// registered in components list bind to the components::Server component.
27///
28/// ## components::Server Dynamic config
29/// * @ref USERVER_LOG_REQUEST
30/// * @ref USERVER_LOG_REQUEST_HEADERS
31/// * @ref USERVER_DEADLINE_PROPAGATION_ENABLED
32/// * @ref USERVER_CANCEL_HANDLE_REQUEST_BY_DEADLINE
33///
34/// ## Static options of components::Server :
35///
36/// Server is configured by 'listener' and 'listener-monitor' entries.
37/// 'listener' is a required entry that describes the request processing
38/// socket. 'listener-monitor' is an optional entry that describes the special
39/// monitoring socket, used for getting statistics and processing utility
40/// requests that should succeed even is the main socket is under heavy pressure.
41///
42/// @include{doc} scripts/docs/en/components_schema/core/src/server/component.md
43///
44/// Options inherited from @ref components::RawComponentBase :
45/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
46///
47/// @see @ref scripts/docs/en/userver/http_server.md
48class Server final : public server::Component {
49public:
50 /// @copydoc server::Component::kName
51 static constexpr std::string_view kName = "server";
52
53 Server(const components::ComponentConfig& component_config, const components::ComponentContext& component_context);
54
55 void OnAllComponentsLoaded() override;
56
57 void OnGracefulShutdown(engine::Deadline serving_shutdown_deadline) override;
58
60
61 const server::Server& GetServer() const override;
62
63 server::Server& GetServer() override;
64
65 void AddHandler(const server::handlers::HttpHandlerBase& handler, engine::TaskProcessor& task_processor);
66
67 static yaml_config::Schema GetStaticConfigSchema();
68
69private:
70 void WriteStatistics(utils::statistics::Writer& writer);
71
72 std::unique_ptr<server::Server> server_;
73};
74
75template <>
76inline constexpr bool kHasValidate<Server> = true;
77
78} // namespace components
79
80USERVER_NAMESPACE_END