rotor
Event loop friendly C++ actor micro-framework
 
Loading...
Searching...
No Matches
supervisor_config.h
1#pragma once
2
3//
4// Copyright (c) 2019-2022 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
5//
6// Distributed under the MIT Software License
7//
8
9#include <atomic>
10#include "policy.h"
11#include "actor_config.h"
12
13#if defined(_MSC_VER)
14#pragma warning(push)
15#pragma warning(disable : 4251)
16#endif
17
18namespace rotor {
19
24
26
29
31 bool create_registry = false;
32
35 bool synchronize_start = false;
36
43
46 size_t inbound_queue_size = 64;
47
57 pt::time_duration poll_duration = pt::millisec{1};
58
65 const std::atomic_bool *shutdown_flag = nullptr;
66
68 pt::time_duration shutdown_poll_frequency = pt::millisec{100};
69};
70
72template <typename Supervisor> struct supervisor_config_builder_t : actor_config_builder_t<Supervisor> {
74 using builder_t = typename Supervisor::template config_builder_t<Supervisor>;
75
78
79 using parent_t::parent_t;
80
82 builder_t &&policy(supervisor_policy_t policy_) &&noexcept {
83 parent_t::config.policy = policy_;
84 return std::move(*static_cast<typename parent_t::builder_t *>(this));
85 }
86
88 builder_t &&create_registry(bool value = true) &&noexcept {
89 parent_t::config.create_registry = value;
90 return std::move(*static_cast<typename parent_t::builder_t *>(this));
91 }
92
94 builder_t &&synchronize_start(bool value = true) &&noexcept {
95 parent_t::config.synchronize_start = value;
96 return std::move(*static_cast<typename parent_t::builder_t *>(this));
97 }
98
100 builder_t &&registry_address(const address_ptr_t &value) &&noexcept {
101 parent_t::config.registry_address = value;
102 return std::move(*static_cast<typename parent_t::builder_t *>(this));
103 }
104
107 builder_t &&inbound_queue_size(size_t value) && {
108 parent_t::config.inbound_queue_size = value;
109 return std::move(*static_cast<builder_t *>(this));
110 }
111
113 builder_t &&poll_duration(const pt::time_duration &value) && {
114 parent_t::config.poll_duration = value;
115 return std::move(*static_cast<builder_t *>(this));
116 }
117
128 builder_t &&shutdown_flag(const std::atomic_bool &value, const pt::time_duration &interval) && {
129 parent_t::config.shutdown_flag = &value;
130 parent_t::config.shutdown_poll_frequency = interval;
131 return std::move(*static_cast<builder_t *>(this));
132 }
133
134 virtual bool validate() noexcept {
135 bool r = parent_t::validate();
136 if (r) {
137 r = !(parent_t::config.registry_address && parent_t::config.create_registry);
138 }
139 return r;
140 }
141};
142
143} // namespace rotor
144
145#if defined(_MSC_VER)
146#pragma warning(pop)
147#endif
Basic namespace for all rotor functionalities.
Definition rotor.hpp:21
intrusive_ptr_t< address_t > address_ptr_t
intrusive pointer for address
Definition address.hpp:57
supervisor_policy_t
how to behave on child actor initialization failures
Definition policy.h:12
@ shutdown_self
shutdown supervisor (and all its actors) if a child-actor fails during supervisor initialization phas...
CRTP actor config builder.
Definition actor_config.h:92
virtual bool validate() noexcept
checks whether config is valid, i.e. all necessary fields are set
Definition actor_config.h:197
config_t config
the currently build config
Definition actor_config.h:128
typename Actor::template config_builder_t< Supervisor > builder_t
final builder class
Definition actor_config.h:94
basic actor configuration: init and shutdown timeouts, etc.
Definition actor_config.h:62
actor_config_t(supervisor_t *supervisor_)
constructs actor_config_t from raw supervisor pointer
Definition actor_config.h:88
CRTP supervisor config builder.
Definition supervisor_config.h:72
builder_t && policy(supervisor_policy_t policy_) &&noexcept
defines actor's startup policy
Definition supervisor_config.h:82
builder_t && create_registry(bool value=true) &&noexcept
instructs supervisor to create an registry
Definition supervisor_config.h:88
virtual bool validate() noexcept
checks whether config is valid, i.e. all necessary fields are set
Definition supervisor_config.h:134
builder_t && inbound_queue_size(size_t value) &&
initial queue size for inbound messages. Makes sense only for root/leader supervisor
Definition supervisor_config.h:107
builder_t && registry_address(const address_ptr_t &value) &&noexcept
injects external registry address
Definition supervisor_config.h:100
typename Supervisor::template config_builder_t< Supervisor > builder_t
final builder class
Definition supervisor_config.h:74
builder_t && shutdown_flag(const std::atomic_bool &value, const pt::time_duration &interval) &&
atomic shutdown flag and the period for polling it
Definition supervisor_config.h:128
builder_t && synchronize_start(bool value=true) &&noexcept
instructs supervisor to synchronize start on it's children actors
Definition supervisor_config.h:94
builder_t && poll_duration(const pt::time_duration &value) &&
how much time spend in active inbound queue polling
Definition supervisor_config.h:113
base supervisor config, which holds shutdown timeout value
Definition supervisor_config.h:23
size_t inbound_queue_size
initial queue size for inbound messages. Makes sense only for root/leader supervisor
Definition supervisor_config.h:46
pt::time_duration shutdown_poll_frequency
the period for checking atomic shutdown flag
Definition supervisor_config.h:68
const std::atomic_bool * shutdown_flag
pointer to atomic shutdown flag for polling (optional)
Definition supervisor_config.h:65
address_ptr_t registry_address
use the specified address of a registry
Definition supervisor_config.h:42
bool create_registry
whether the registry actor should be instantiated by supervisor
Definition supervisor_config.h:31
bool synchronize_start
whether supervisor should wait until all actors confirmed initialization, and only then send start si...
Definition supervisor_config.h:35
supervisor_policy_t policy
how to behave if child-actor fails
Definition supervisor_config.h:28
pt::time_duration poll_duration
How much time it will spend in polling inbound queue before switching into sleep mode (i....
Definition supervisor_config.h:57