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/components/component_base.hpp>
9#include <userver/engine/task/task_processor_fwd.hpp>
10#include <userver/server/server.hpp>
11#include <userver/utils/statistics/entry.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 ComponentBase {
49public:
50 /// @ingroup userver_component_names
51 /// @brief The default name of @ref components::Server component
52 static constexpr std::string_view kName = "server";
53
54 Server(const components::ComponentConfig& component_config, const components::ComponentContext& component_context);
55
56 ~Server() override;
57
58 void OnAllComponentsLoaded() override;
59
61
62 const server::Server& GetServer() const;
63
64 server::Server& GetServer();
65
66 void AddHandler(const server::handlers::HttpHandlerBase& handler, engine::TaskProcessor& task_processor);
67
68 static yaml_config::Schema GetStaticConfigSchema();
69
70private:
71 void WriteStatistics(utils::statistics::Writer& writer);
72
73 std::unique_ptr<server::Server> server_;
74 utils::statistics::Entry server_statistics_holder_;
75 utils::statistics::Entry handler_statistics_holder_;
76};
77
78template <>
79inline constexpr bool kHasValidate<Server> = true;
80
81} // namespace components
82
83USERVER_NAMESPACE_END