userver: userver/dynamic_config/updates_sink/component.hpp Source File
Loading...
Searching...
No Matches
component.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/dynamic_config/updates_sink/component.hpp
4/// @brief @copybrief components::DynamicConfigUpdatesSinkBase
5
6#include <memory>
7#include <string_view>
8
9#include <userver/components/loggable_component_base.hpp>
10#include <userver/dynamic_config/fwd.hpp>
11
12USERVER_NAMESPACE_BEGIN
13
14namespace components {
16} // namespace components
17
18namespace dynamic_config::impl {
19void RegisterUpdater(components::DynamicConfigUpdatesSinkBase& sink,
20 std::string_view sink_component_name,
21 std::string_view updater_component_name);
22} // namespace dynamic_config::impl
23
24namespace components {
25
26/// @ingroup userver_base_classes
27///
28/// @brief Base class for components acting as dynamic config updates sinks.
29///
30/// Dynamic config updaters (see components::DynamicConfigClientUpdater for
31/// example) internally look for updates sink object using
32/// dynamic_config::FindUpdatesSink function and use it to store received
33/// updates to the dynamic config. By default, this function returns
34/// components::DynamicConfig itself, however some user-defined components may
35/// inherit from components::DynamicConfigUpdatesSinkBase to apply various
36/// transformations to parameters before storing them to dynamic config.
37///
38/// @warning Unless explicitly stated, descendants of this class expect that
39/// `SetConfig` method calls are serialized.
41 public:
42 DynamicConfigUpdatesSinkBase(const components::ComponentConfig&,
43 const components::ComponentContext&);
44
45 ~DynamicConfigUpdatesSinkBase() override;
46
47 /// Called by updaters to store new version of dynamic config.
48 /// @param updater updater name used for logging
49 /// @param config updated dynamic config
50 virtual void SetConfig(std::string_view updater,
51 dynamic_config::DocsMap&& config) = 0;
52
53 /// Called by updaters to store new version of dynamic config.
54 /// Default implementation creates a copy of `config` and then uses it
55 /// in the call to `SetConfig` overload with an rvalue `DocsMap` parameter.
56 /// @param updater updater name used for logging
57 /// @param config updated dynamic config
58 virtual void SetConfig(std::string_view updater,
59 const dynamic_config::DocsMap& config);
60
61 /// Called when updater failed to load dynamic config.
62 /// When service is started and dynamic config cache file is not found,
63 /// components::DynamicConfig expects updater to provide current version of
64 /// the dynamic config and blocks all reads until it is received. Updater is
65 /// expected to call this method if it can't load dynamic config.
66 /// @param updater updater name used for logging
67 /// @param error error to be outputted to log
68 virtual void NotifyLoadingFailed(std::string_view updater,
69 std::string_view error) = 0;
70
71 private:
72 struct UsedByInfo;
73
74 friend void dynamic_config::impl::RegisterUpdater(
76 std::string_view sink_component_name,
77 std::string_view updater_component_name);
78
79 std::unique_ptr<UsedByInfo> used_by_;
80};
81
82} // namespace components
83
84USERVER_NAMESPACE_END