rotor
Event loop friendly C++ actor micro-framework
 
Loading...
Searching...
No Matches
spawner.h
1#pragma once
2
3//
4// Copyright (c) 2022 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
5//
6// Distributed under the MIT Software License
7//
8
9#include "forward.hpp"
10#include "policy.h"
11
12#if defined(_MSC_VER)
13#pragma warning(push)
14#pragma warning(disable : 4251)
15#endif
16
17namespace rotor {
18
19namespace details {
20enum class request_state_t { NONE, SENT, CONFIRMED };
21}
22
30struct ROTOR_API spawner_t {
31 ~spawner_t();
32
38 spawner_t &&restart_period(const pt::time_duration &) noexcept;
39
42
49 spawner_t &&max_attempts(size_t) noexcept;
50
57 spawner_t &&escalate_failure(bool = true) noexcept;
58
62 void spawn() noexcept;
63
64 private:
65 spawner_t(factory_t factory, supervisor_t &supervisor) noexcept;
66
67 factory_t factory;
68 supervisor_t &supervisor;
69 pt::time_duration period = pt::seconds{15};
70 restart_policy_t policy = restart_policy_t::normal_only;
71 size_t attempts = 0;
72 bool done = false;
73 bool escalate = false;
74
75 friend struct supervisor_t;
76};
77
78} // namespace rotor
79
80#if defined(_MSC_VER)
81#pragma warning(pop)
82#endif
Basic namespace for all rotor functionalities.
Definition rotor.hpp:21
restart_policy_t
spawner's actor restart policy
Definition policy.h:23
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
allows automatically restart actors
Definition spawner.h:30
spawner_t && restart_period(const pt::time_duration &) noexcept
minimum amount of time before respawning new actor
spawner_t && restart_policy(restart_policy_t) noexcept
determines whether new actor instance should be spawned
spawner_t && max_attempts(size_t) noexcept
maximum amount of spawned actor instances
spawner_t && escalate_failure(bool=true) noexcept
shutdown actor when the spawned actor crashed
supervisor is responsible for managing actors (workers) lifetime
Definition supervisor.h:69