userver: userver/components/loggable_component_base.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
loggable_component_base.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/components/loggable_component_base.hpp
4/// @brief Contains components::LoggableComponentBase declaration and forward
5/// declarations of components::ComponentConfig and
6/// components::ComponentContext, function components::GetCurrentComponentName()
7
8#include <userver/components/component_fwd.hpp>
9#include <userver/components/impl/component_base.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace components {
14
15/// @ingroup userver_base_classes
16///
17/// @brief Base class for all @ref userver_components "application components",
18/// it depends on components::Logger and components::Tracer.
19class LoggableComponentBase : public impl::ComponentBase {
20 public:
21 LoggableComponentBase(const ComponentConfig&, const ComponentContext&);
22
23 LoggableComponentBase(LoggableComponentBase&&) = delete;
24 LoggableComponentBase(const LoggableComponentBase&) = delete;
25
26 /// It is a good place to stop your work here.
27 /// All components dependent on the current component were destroyed.
28 /// All components on which the current component depends are still alive.
29 ~LoggableComponentBase() override = default;
30
31 /// Override this function to inform the world of the state of your
32 /// component.
33 ///
34 /// @warning The function is called concurrently from multiple threads.
37 }
38
39 /// Called once if the creation of any other component failed.
40 /// If the current component expects some other component to take any action
41 /// with the current component, this call is a signal that such action may
42 /// never happen due to components loading was cancelled.
43 /// Application components might not want to override it.
44 void OnLoadingCancelled() override {}
45
46 /// Component may use this function to finalize registration of other
47 /// components that depend on it (for example, handler components register
48 /// in server component, and the latter uses OnAllComponentsLoaded() to start
49 /// processing requests).
50 ///
51 /// Base components may override it and make `final` to do some work after the
52 /// derived object constructor is called. Don't use it otherwise.
53 void OnAllComponentsLoaded() override {}
54
55 /// Component may use this function to stop doing work before the stop of the
56 /// components that depend on it.
57 ///
58 /// Base components may override it and make `final` to do some work before
59 /// the derived object constructor is called. Don't use it otherwise.
60 void OnAllComponentsAreStopping() override {}
61
62 static yaml_config::Schema GetStaticConfigSchema();
63};
64
65} // namespace components
66
67USERVER_NAMESPACE_END