10#include <userver/components/loggable_component_base.hpp>
11#include <userver/engine/mutex.hpp>
13USERVER_NAMESPACE_BEGIN
19class ComponentControl
final {
21 void InvalidateComponents();
24 friend class ComponentInvalidatorHolder;
26 using Callback = std::function<
void()>;
27 using InvalidatorList = std::list<Callback>;
28 using InvalidatorHandle = InvalidatorList::iterator;
30 InvalidatorHandle RegisterComponentInvalidator(Callback&& callback);
32 void UnregisterComponentInvalidator(InvalidatorHandle handle)
noexcept;
35 InvalidatorList invalidators_;
39class ComponentInvalidatorHolder
final {
42 ComponentInvalidatorHolder(ComponentControl& component_control, T& component,
43 void (T::*invalidate_method)())
44 : ComponentInvalidatorHolder(component_control,
45 [&component, invalidate_method] {
46 (component.*invalidate_method)();
50 "ComponentInvalidatorHolder can only be used with components");
53 ~ComponentInvalidatorHolder();
55 ComponentInvalidatorHolder(
const ComponentInvalidatorHolder&) =
delete;
56 ComponentInvalidatorHolder(ComponentInvalidatorHolder&&) =
delete;
57 ComponentInvalidatorHolder& operator=(
const ComponentInvalidatorHolder&) =
59 ComponentInvalidatorHolder& operator=(ComponentInvalidatorHolder&&) =
delete;
62 ComponentInvalidatorHolder(ComponentControl& component_control,
63 std::function<
void()>&& callback);
65 ComponentControl& component_control_;
66 ComponentControl::InvalidatorHandle invalidator_handle_;