123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- #pragma once
- #include <atomic>
- #include "policy.h"
- #include "actor_config.h"
- #if defined(_MSC_VER)
- #pragma warning(push)
- #pragma warning(disable : 4251)
- #endif
- namespace rotor {
- struct supervisor_config_t : actor_config_t {
- using actor_config_t::actor_config_t;
-
- supervisor_policy_t policy = supervisor_policy_t::shutdown_self;
-
- bool create_registry = false;
-
- bool synchronize_start = false;
-
- address_ptr_t registry_address;
-
- size_t inbound_queue_size = 64;
-
- pt::time_duration poll_duration = pt::millisec{1};
-
- const std::atomic_bool *shutdown_flag = nullptr;
-
- pt::time_duration shutdown_poll_frequency = pt::millisec{100};
- };
- template <typename Supervisor> struct supervisor_config_builder_t : actor_config_builder_t<Supervisor> {
-
- using builder_t = typename Supervisor::template config_builder_t<Supervisor>;
-
- using parent_t = actor_config_builder_t<Supervisor>;
- using parent_t::parent_t;
-
- builder_t &&policy(supervisor_policy_t policy_) &&noexcept {
- parent_t::config.policy = policy_;
- return std::move(*static_cast<typename parent_t::builder_t *>(this));
- }
-
- builder_t &&create_registry(bool value = true) &&noexcept {
- parent_t::config.create_registry = value;
- return std::move(*static_cast<typename parent_t::builder_t *>(this));
- }
-
- builder_t &&synchronize_start(bool value = true) &&noexcept {
- parent_t::config.synchronize_start = value;
- return std::move(*static_cast<typename parent_t::builder_t *>(this));
- }
-
- builder_t &®istry_address(const address_ptr_t &value) &&noexcept {
- parent_t::config.registry_address = value;
- return std::move(*static_cast<typename parent_t::builder_t *>(this));
- }
-
- builder_t &&inbound_queue_size(size_t value) && {
- parent_t::config.inbound_queue_size = value;
- return std::move(*static_cast<builder_t *>(this));
- }
-
- builder_t &&poll_duration(const pt::time_duration &value) && {
- parent_t::config.poll_duration = value;
- return std::move(*static_cast<builder_t *>(this));
- }
-
- builder_t &&shutdown_flag(const std::atomic_bool &value, const pt::time_duration &interval) && {
- parent_t::config.shutdown_flag = &value;
- parent_t::config.shutdown_poll_frequency = interval;
- return std::move(*static_cast<builder_t *>(this));
- }
- virtual bool validate() noexcept {
- bool r = parent_t::validate();
- if (r) {
- r = !(parent_t::config.registry_address && parent_t::config.create_registry);
- }
- return r;
- }
- };
- }
- #if defined(_MSC_VER)
- #pragma warning(pop)
- #endif
|