#include <userver/dynamic_config/source.hpp>
A client for easy dynamic config fetching in components.
After construction, dynamic_config::Source can be copied around and passed to clients or child helper classes.
Usually retrieved from components::DynamicConfig component.
Typical usage:
Definition at line 91 of file source.hpp.
Public Types | |
| using | SnapshotEventSource = concurrent::AsyncEventSource<const Snapshot&> |
| using | DiffEventSource = concurrent::AsyncEventSource<const Diff&> |
Public Member Functions | |
| Source (impl::StorageData &storage) | |
| Source (const Source &)=default | |
| Source (Source &&)=default | |
| Source & | operator= (const Source &)=default |
| Source & | operator= (Source &&)=default |
| Snapshot | GetSnapshot () const |
| template<typename VariableType> | |
| VariableSnapshotPtr< VariableType > | GetSnapshot (const Key< VariableType > &key) const |
| template<typename VariableType> | |
| VariableType | GetCopy (const Key< VariableType > &key) const |
| template<typename Class> | |
| void | UpdateAndListen (utils::ResourceScopeStorage &scopes, Class *obj, std::string_view name, void(Class::*func)(const dynamic_config::Snapshot &config)) |
| template<typename Class> | |
| concurrent::AsyncEventSubscriberScope | UpdateAndListen (Class *obj, std::string_view name, void(Class::*func)(const dynamic_config::Snapshot &config)) |
| template<typename Class> | |
| void | UpdateAndListen (utils::ResourceScopeStorage &scopes, Class *obj, std::string_view name, void(Class::*func)(const dynamic_config::Diff &diff)) |
| Subscribes to dynamic-config updates with information about the current and previous states. | |
| template<typename Class> | |
| concurrent::AsyncEventSubscriberScope | UpdateAndListen (Class *obj, std::string_view name, void(Class::*func)(const dynamic_config::Diff &diff)) |
| template<typename Class, typename... Keys> | |
| void | UpdateAndListen (utils::ResourceScopeStorage &scopes, Class *obj, std::string_view name, void(Class::*func)(const dynamic_config::Snapshot &config), const Keys &... keys) |
| Subscribes to updates of a subset of all configs. | |
| template<typename Class, typename... Keys> | |
| concurrent::AsyncEventSubscriberScope | UpdateAndListen (Class *obj, std::string_view name, void(Class::*func)(const dynamic_config::Snapshot &config), const Keys &... keys) |
| SnapshotEventSource & | GetEventChannel () |
| using dynamic_config::Source::DiffEventSource = concurrent::AsyncEventSource<const Diff&> |
Definition at line 94 of file source.hpp.
| using dynamic_config::Source::SnapshotEventSource = concurrent::AsyncEventSource<const Snapshot&> |
Definition at line 93 of file source.hpp.
|
explicit |
For internal use only. Obtain using components::DynamicConfig or dynamic_config::StorageMock instead.
|
inline |
Definition at line 114 of file source.hpp.
|
inline |
Definition at line 109 of file source.hpp.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Store the returned scope as a member and call Unsubscribe explicitly.
Definition at line 220 of file source.hpp.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Store the returned scope as a member and call Unsubscribe explicitly.
Definition at line 158 of file source.hpp.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Store the returned scope as a member and call Unsubscribe explicitly.
Definition at line 279 of file source.hpp.
|
inline |
Subscribes to dynamic-config updates with information about the current and previous states.
Subscribes to dynamic-config updates using a member function, named OnConfigUpdate by convention. Also constructs dynamic_config::Diff object using std::nullopt and current config snapshot, then immediately invokes the function with it (this invocation will be executed synchronously).
Further updates are delivered after utils::ResourceScopeStorage::AfterConstruction, including those updates that arrived before it. Unsubscribe runs in utils::ResourceScopeStorage::BeforeDestruction.
Example usage:
| scopes | storage that owns the subscription lifetime. See where to obtain scopes. |
| obj | the subscriber, which is the owner of the listener method, and is also used as the unique identifier of the subscription |
| name | the name of the subscriber, for diagnostic purposes |
| func | the listener method, named OnConfigUpdate by convention. |
Definition at line 203 of file source.hpp.
|
inline |
Subscribes to dynamic-config updates using a member function. Also immediately invokes the function with the current config snapshot (this invocation will be executed synchronously).
Further updates are delivered after utils::ResourceScopeStorage::AfterConstruction, including those updates that arrived before it. Unsubscribe runs in utils::ResourceScopeStorage::BeforeDestruction.
| scopes | storage that owns the subscription lifetime. See where to obtain scopes. |
| obj | the subscriber, which is the owner of the listener method, and is also used as the unique identifier of the subscription |
| name | the name of the subscriber, for diagnostic purposes |
| func | the listener method, named OnConfigUpdate by convention. |
Definition at line 138 of file source.hpp.
|
inline |
Subscribes to updates of a subset of all configs.
Subscribes to dynamic-config updates using a member function, named OnConfigUpdate by convention. The function will be invoked if at least one of the configs has been changed since the previous invocation. So at the first time immediately invokes the function with the current config snapshot (this invocation will be executed synchronously).
Further updates are delivered after utils::ResourceScopeStorage::AfterConstruction, including those updates that arrived before it. Unsubscribe runs in utils::ResourceScopeStorage::BeforeDestruction.
| scopes | storage that owns the subscription lifetime. See where to obtain scopes. |
| obj | the subscriber, which is the owner of the listener method, and is also used as the unique identifier of the subscription |
| name | the name of the subscriber, for diagnostic purposes |
| func | the listener method, named OnConfigUpdate by convention. |
| keys | config objects, specializations of dynamic_config::Key. |
Definition at line 257 of file source.hpp.