userver
C++ Async Framework
Loading...
Searching...
No Matches
component_base.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/components/component_base.hpp
4
/// @brief Contains components::ComponentBase 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
/
raw_component_base
.
hpp
>
10
11
USERVER_NAMESPACE_BEGIN
12
13
namespace
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.
19
class
ComponentBase
:
public
RawComponentBase
{
20
public
:
21
ComponentBase(
const
ComponentConfig&,
const
ComponentContext&);
22
23
ComponentBase(
ComponentBase
&&) =
delete
;
24
ComponentBase(
const
ComponentBase
&) =
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
~
ComponentBase
()
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.
35
ComponentHealth
GetComponentHealth
()
const
override
{
36
return
ComponentHealth
::
kOk
;
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
/// If the component pulls more options from @ref ComponentConfig than its
63
/// parent component, then it needs to define `GetStaticConfigSchema` method
64
/// and add its own options to the parent component's options.
65
static
yaml_config
::Schema
GetStaticConfigSchema
();
66
67
protected
:
68
/// Legacy alias, use @ref ComponentBase instead.
69
using
LoggableComponentBase =
ComponentBase
;
70
};
71
72
/// Deprecated, use @ref ComponentBase instead.
73
using
LoggableComponentBase =
ComponentBase
;
74
75
}
// namespace components
76
77
USERVER_NAMESPACE_END
userver
components
component_base.hpp
Generated on Thu Sep 5 2024 11:16:22 for userver by
Doxygen
1.10.0