9#include "rotor/forward.hpp"
10#include "rotor/policy.h"
15#pragma warning(disable : 4251)
18namespace rotor::detail {
20enum class shutdown_state_t { none, sent, confirmed };
28using spawn_demand_t = std::variant<demand::no, demand::now, demand::escalate_failure, pt::time_duration>;
36struct ROTOR_API
child_info_t : boost::intrusive_ref_counter<child_info_t, boost::thread_unsafe_counter> {
41 template <
typename Factory>
43 const pt::time_duration &restart_period_ = pt::seconds{15},
size_t max_attempts_ = 0,
44 bool escalate_failure_ =
false)
noexcept
45 : address{std::move(address_)}, factory{std::forward<Factory>(factory_)}, policy{policy_},
46 restart_period{restart_period_}, max_attempts{max_attempts_}, escalate_failure{escalate_failure_} {}
49 template <
typename Factory,
typename Actor>
51 :
child_info_t(std::move(address_), std::forward<Factory>(factory_)) {
52 actor = std::forward<Actor>(actor_);
73 spawn_demand_t
next_spawn(
bool abnormal_shutdown) noexcept;
91 shutdown_state_t
shutdown = shutdown_state_t::none;
118using child_info_ptr_t = boost::intrusive_ptr<child_info_t>;
std::function< actor_ptr_t(supervisor_t &, const address_ptr_t &)> factory_t
factory which allows to create actors lazily or on demand
Definition forward.hpp:45
restart_policy_t
spawner's actor restart policy
Definition policy.h:23
@ normal_only
restart actor only when it terminated normally (without error)
Definition policy.h:35
intrusive_ptr_t< actor_base_t > actor_ptr_t
intrusive pointer for actor
Definition forward.hpp:23
intrusive_ptr_t< address_t > address_ptr_t
intrusive pointer for address
Definition address.hpp:57
std::size_t request_id_t
timer identifier type in the scope of the actor
Definition forward.hpp:34
actor_ptr_t actor
owning reference to current actor instance
Definition child_info.h:82
bool initialized
whether actor is initialized
Definition child_info.h:112
restart_policy_t policy
restart policy (used by spawner)
Definition child_info.h:85
pt::time_duration restart_period
minimum amount of time between spawning attempts
Definition child_info.h:88
shutdown_state_t shutdown
actor shutdown substate
Definition child_info.h:91
factory_t factory
actor's factory (used by spawner)
Definition child_info.h:79
size_t attempts
the current number of restart attempts
Definition child_info.h:97
bool escalate_failure
whether an actor failure should be escalated to supervisor
Definition child_info.h:103
pt::microsec_clock clock_t
an alias for used microsec clock
Definition child_info.h:38
child_info_t(address_ptr_t address_, Factory &&factory_, restart_policy_t policy_=restart_policy_t::normal_only, const pt::time_duration &restart_period_=pt::seconds{15}, size_t max_attempts_=0, bool escalate_failure_=false) noexcept
CTOR for spawner-instantiated actor.
Definition child_info.h:42
bool started
whether actor is started
Definition child_info.h:115
bool active
whether the spawner is active
Definition child_info.h:100
address_ptr_t address
actor's address
Definition child_info.h:76
spawn_demand_t next_spawn(bool abnormal_shutdown) noexcept
checks whether new actor should be spawned
pt::ptime last_instantiation
when an actor was successfully spawned
Definition child_info.h:109
void spawn_attempt() noexcept
recalculates the state upon spawn_attempt
request_id_t timer_id
the timer_id when actor should be spawned
Definition child_info.h:106
size_t max_attempts
maximum restart attempts (used by spawner)
Definition child_info.h:94
child_info_t(address_ptr_t address_, Factory &&factory_, Actor &&actor_) noexcept
CTOR for manually instantiated actor.
Definition child_info.h:50
Definition child_info.h:25
Definition child_info.h:23
Definition child_info.h:24