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
{
return
ComponentHealth
::
kOk
; }
36
37
/// Called once if the creation of any other component failed.
38
/// If the current component expects some other component to take any action
39
/// with the current component, this call is a signal that such action may
40
/// never happen due to components loading was cancelled.
41
/// Application components might not want to override it.
42
void
OnLoadingCancelled
()
override
{}
43
44
/// Component may use this function to finalize registration of other
45
/// components that depend on it (for example, handler components register
46
/// in server component, and the latter uses OnAllComponentsLoaded() to start
47
/// processing requests).
48
///
49
/// Base components may override it and make `final` to do some work after the
50
/// derived object constructor is called. Don't use it otherwise.
51
void
OnAllComponentsLoaded
()
override
{}
52
53
/// Serving components like HTTP and gRPC servers may use this function to stop accepting new requests
54
/// and shutdown serving in the given time interval.
55
/// Application components likely do not need to override it.
56
///
57
/// @param[in] serving_shutdown_deadline The deadline until already running requests should be allowed
58
/// to complete.
59
/// The component is supposed to stop accepting new requests and continue processing of already
60
/// active requests until this deadline (unless those requests finish earlier).
61
/// And it might completely shutdown requests processing when the deadline is reached
62
/// (or when no active requests left).
63
void
OnGracefulShutdown
(engine::Deadline
/*serving_shutdown_deadline*/
)
override
;
64
65
/// Component may use this function to stop doing work before the stop of the
66
/// components that depend on it.
67
///
68
/// Base components may override it and make `final` to do some work before
69
/// the derived object constructor is called. Don't use it otherwise.
70
void
OnAllComponentsAreStopping
()
override
{}
71
72
/// If the component pulls more options from @ref components::ComponentConfig than its
73
/// parent component, then it needs to define `GetStaticConfigSchema` method
74
/// and add its own options to the parent component's options.
75
static
yaml_config::Schema
GetStaticConfigSchema
();
76
77
protected
:
78
/// @deprecated use @ref components::ComponentBase instead.
79
using
LoggableComponentBase =
ComponentBase
;
80
};
81
82
/// @deprecated use @ref components::ComponentBase instead.
83
using
LoggableComponentBase =
ComponentBase
;
84
85
/// @see @ref components::LocateDependency
86
template
<
typename
T>
87
struct
WithType
{};
88
89
}
// namespace components
90
91
USERVER_NAMESPACE_END
userver
components
component_base.hpp
Generated on Thu May 21 2026 16:16:03 for userver by
Doxygen
1.13.2