rotor
Event loop friendly C++ actor micro-framework
 
Loading...
Searching...
No Matches
child_manager.h
1#pragma once
2
3//
4// Copyright (c) 2019-2023 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
5//
6// Distributed under the MIT Software License
7//
8
9#include "plugin_base.h"
10#include <unordered_set>
11#include "rotor/detail/child_info.h"
12
13#if defined(_MSC_VER)
14#pragma warning(push)
15#pragma warning(disable : 4251)
16#endif
17
18namespace rotor::plugin {
19
30struct ROTOR_API child_manager_plugin_t : public plugin_base_t {
31 using plugin_base_t::plugin_base_t;
32
34 static const std::type_index class_identity;
35
36 const std::type_index &identity() const noexcept override;
37
38 void activate(actor_base_t *actor) noexcept override;
39 void deactivate() noexcept override;
40
42 virtual void create_child(const actor_ptr_t &actor) noexcept;
43
46 virtual void spawn(factory_t factory, const pt::time_duration &period, restart_policy_t policy, size_t max_attempts,
47 bool escalate) noexcept;
48
55 virtual void remove_child(const actor_base_t &actor) noexcept;
56
61 virtual void on_shutdown_fail(actor_base_t &actor, const extended_error_ptr_t &ec) noexcept;
62
64 virtual void on_create(message::create_actor_t &message) noexcept;
65
74 virtual void on_init(message::init_response_t &message) noexcept;
75
84 virtual void on_shutdown_trigger(message::shutdown_trigger_t &message) noexcept;
85
87 virtual void on_shutdown_confirm(message::shutdown_response_t &message) noexcept;
88
90 virtual void on_spawn(message::spawn_actor_t &message) noexcept;
91
92 bool handle_init(message::init_request_t *) noexcept override;
93 bool handle_shutdown(message::shutdown_request_t *) noexcept override;
94 void handle_start(message::start_trigger_t *message) noexcept override;
95
96 bool handle_unsubscription(const subscription_point_t &point, bool external) noexcept override;
97
99 template <typename T> auto &access() noexcept;
100
101 private:
102 using actors_map_t = std::unordered_map<address_ptr_t, detail::child_info_ptr_t>;
103 using spawning_map_t = std::unordered_map<request_id_t, detail::child_info_ptr_t>;
104
105 bool has_initializing() const noexcept;
106 void init_continue() noexcept;
107 void request_shutdown(const extended_error_ptr_t &ec) noexcept;
108 void cancel_init(const actor_base_t *child) noexcept;
109 void request_shutdown(detail::child_info_t &child_state, const extended_error_ptr_t &ec) noexcept;
110 void on_spawn_timer(request_id_t timer_id, bool cancelled) noexcept;
111
112 size_t active_actors() noexcept;
113
115 using initializing_actors_t = std::unordered_set<address_ptr_t>;
116
118 actors_map_t actors_map;
119 spawning_map_t spawning_map;
120};
121
122} // namespace rotor::plugin
123
124#if defined(_MSC_VER)
125#pragma warning(pop)
126#endif
intrusive_ptr_t< address_t > address_ptr_t
intrusive pointer for address
Definition address.hpp:57
intrusive_ptr_t< extended_error_t > extended_error_ptr_t
intrusive pointer to extended error type
Definition extended_error.h:25
restart_policy_t
spawner's actor restart policy
Definition policy.h:23
intrusive_ptr_t< actor_base_t > actor_ptr_t
intrusive pointer for actor
Definition forward.hpp:23
std::size_t request_id_t
timer identifier type in the scope of the actor
Definition forward.hpp:34
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
universal primitive of concurrent computation
Definition actor_base.h:47
supervisor's plugin for child-actors housekeeping
Definition child_manager.h:30
static const std::type_index class_identity
Definition child_manager.h:34
const std::type_index & identity() const noexcept override
returns pointer, which uniquely identifiess plugin type
base class for all actor plugins
Definition plugin_base.h:23
pair of handler_base_t linked to particular address_t
Definition subscription_point.h:50