#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 77 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 > | |
concurrent::AsyncEventSubscriberScope | UpdateAndListen (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::Diff &diff)) |
Subscribes to dynamic-config updates with information about the current and previous states. | |
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) |
Subscribes to updates of a subset of all configs. | |
SnapshotEventSource & | GetEventChannel () |
using dynamic_config::Source::DiffEventSource = concurrent::AsyncEventSource<const Diff&> |
Definition at line 80 of file source.hpp.
Definition at line 79 of file source.hpp.
|
explicit |
For internal use only. Obtain using components::DynamicConfig or dynamic_config::StorageMock instead.
|
inline |
Definition at line 101 of file source.hpp.
|
inline |
Definition at line 95 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).
components::DynamicConfigClientUpdater
options.std::nullopt
and current config snapshot.Example usage:
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. |
concurrent::AsyncEventSubscriberScope
controlling the subscription, which should be stored as a member in the subscriber; Unsubscribe
should be called explicitlyDefinition at line 167 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).
components::DynamicConfigClientUpdater
options.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. |
concurrent::AsyncEventSubscriberScope
controlling the subscription, which should be stored as a member in the subscriber; Unsubscribe
should be called explicitlyDefinition at line 123 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).
operator==
.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 . |
concurrent::AsyncEventSubscriberScope
controlling the subscription, which should be stored as a member in the subscriber; Unsubscribe
should be called explicitlyDefinition at line 199 of file source.hpp.