rotor
Event loop friendly C++ actor micro-framework
Loading...
Searching...
No Matches
rotor::registry_t Struct Reference

keeps name-to-service_address mapping at runtime More...

#include <registry.h>

Inheritance diagram for rotor::registry_t:
rotor::actor_base_t

Public Member Functions

void configure (plugin::plugin_base_t &plugin) noexcept override
 main callback for plugin configuration when it's ready
virtual void on_reg (message::registration_request_t &request) noexcept
 registers address on the service. Fails, if the name already exists
virtual void on_dereg_service (message::deregistration_service_t &message) noexcept
 deregisters the name in the registry
virtual void on_dereg (message::deregistration_notify_t &message) noexcept
 deregisters all names associated with the service address
virtual void on_discovery (message::discovery_request_t &request) noexcept
 returns service address associated with the name or error
virtual void on_promise (message::discovery_promise_t &request) noexcept
 notify the requestee when service name/address becomes available
virtual void on_cancel (message::discovery_cancel_t &notify) noexcept
 cancels previously asked discovery promise
template<typename T>
auto & access () noexcept
 generic non-public fields accessor
 actor_base_t (config_t &cfg)
 constructs actor and links it's supervisor
Public Member Functions inherited from rotor::actor_base_t
 actor_base_t (config_t &cfg)
 constructs actor and links it's supervisor
virtual void do_initialize (system_context_t *ctx) noexcept
 early actor initialization (pre-initialization)
virtual void do_shutdown (const extended_error_ptr_t &reason={}) noexcept
 convenient method to send actor's supervisor shutdown trigger message
virtual void on_start () noexcept
 actor is fully initialized and it's supervisor has sent signal to start
template<typename M, typename... Args>
void send (const address_ptr_t &addr, Args &&...args)
 sends message to the destination address
template<typename M, typename... Args>
void route (const address_ptr_t &addr, const address_ptr_t &next_addr, Args &&...args)
 routes message to the destination address, then to the next address
void redirect (message_ptr_t message, const address_ptr_t &addr, const address_ptr_t &next_addr={}) noexcept
 redirects premade message into destination address (and them, possibly routes it to `next_address)
template<typename R, typename... Args>
request_builder_t< typename request_wrapper_t< R >::request_t > request (const address_ptr_t &dest_addr, Args &&...args)
 returns request builder for destination address using the "main" actor address
template<typename R, typename... Args>
request_builder_t< typename request_wrapper_t< R >::request_t > request_via (const address_ptr_t &dest_addr, const address_ptr_t &reply_addr, Args &&...args)
 returns request builder for destination address using the specified address for reply
template<typename Request, typename... Args>
void reply_to (Request &message, Args &&...args)
 convenient method for constructing and sending response to a request
template<typename Request>
void reply_with_error (Request &message, const extended_error_ptr_t &ec)
 convenient method for constructing and sending error response to a request
template<typename Request, typename... Args>
auto make_response (Request &message, Args &&...args)
 makes response to the request, but does not send it.
template<typename Request>
auto make_response (Request &message, const extended_error_ptr_t &ec)
 makes error response to the request, but does not send it.
template<typename Handler>
subscription_info_ptr_t subscribe (Handler &&h, const address_ptr_t &addr) noexcept
 subscribes actor's handler to process messages on the specified address
template<typename Handler>
subscription_info_ptr_t subscribe (Handler &&h) noexcept
 subscribes actor's handler to process messages on the actor's "main" address
template<typename Handler, typename = is_handler<Handler>>
void unsubscribe (Handler &&h, address_ptr_t &addr) noexcept
 unsubscribes actor's handler from process messages on the specified address
template<typename Handler, typename = is_handler<Handler>>
void unsubscribe (Handler &&h) noexcept
 unsubscribes actor's handler from processing messages on the actor's "main" address
void unsubscribe (const handler_ptr_t &h) noexcept
 initiates handler unsubscription from the default actor address
void activate_plugins () noexcept
 starts plugins activation
void commit_plugin_activation (plugin::plugin_base_t &plugin, bool success) noexcept
 finishes plugin activation, successful or not
void deactivate_plugins () noexcept
 starts plugins deactivation
void commit_plugin_deactivation (plugin::plugin_base_t &plugin) noexcept
 finishes plugin deactivation
void on_subscription (message::subscription_t &message) noexcept
 propagates subscription message to corresponding actors
void on_unsubscription (message::unsubscription_t &message) noexcept
 propagates unsubscription message to corresponding actors
void on_unsubscription_external (message::unsubscription_external_t &message) noexcept
 propagates external unsubscription message to corresponding actors
address_ptr_t create_address () noexcept
 creates new unique address for an actor (via address_maker plugin)
virtual void shutdown_start () noexcept
 starts shutdown procedure, e.g. upon receiving shutdown request
void shutdown_continue () noexcept
 polls plugins for shutdown
virtual void shutdown_finish () noexcept
 finalizes shutdown
virtual void init_start () noexcept
 starts initialization procedure
void init_continue () noexcept
 polls plugins whether they completed initialization.
virtual void init_finish () noexcept
 finalizes initialization
template<typename T>
auto & access () noexcept
 generic non-public fields accessor
template<typename T, typename... Args>
auto access (Args... args) noexcept
 generic non-public methods accessor
template<typename T>
auto & access () const noexcept
 generic non-public fields accessor
template<typename T, typename... Args>
auto access (Args... args) const noexcept
 generic non-public methods accessor
const address_ptr_tget_address () const noexcept
 returns actor's main address
supervisor_tget_supervisor () const noexcept
 returns actor's supervisor
template<typename Delegate, typename Method, typename = std::enable_if_t<std::is_invocable_v<Method, Delegate *, request_id_t, bool>>>
request_id_t start_timer (const pt::time_duration &interval, Delegate &delegate, Method method) noexcept
 spawns a new one-shot timer
void cancel_timer (request_id_t request_id) noexcept
 cancels previously started timer
const extended_error_ptr_tget_shutdown_reason () const noexcept
 returns actor shutdown reason
const std::string & get_identity () const noexcept
 retuns human-readable actor identity
virtual bool should_restart () const noexcept
 whether spawner should create a new instance of the actor
template<typename Request, typename... Args>
request_builder_t< typename request_wrapper_t< Request >::request_t > request (const address_ptr_t &dest_addr, Args &&...args)
 makes an request to the destination address with the message constructed from args
template<typename Request, typename... Args>
request_builder_t< typename request_wrapper_t< Request >::request_t > request_via (const address_ptr_t &dest_addr, const address_ptr_t &reply_addr, Args &&...args)
 makes an request to the destination address with the message constructed from args

Protected Types

using promise_ptr_t = intrusive_ptr_t<message::discovery_promise_t>
 intrusive pointer to discovery promise message (type)
using promises_list_t = std::list<promise_ptr_t>
 list of intrusive pointers to discovery promise messages (type)
using registered_map_t = std::unordered_map<std::string, address_ptr_t>
 name-to-address mapping type
using registered_names_t = std::set<std::string>
 set of registered names type (for single address)
using reverse_map_t = std::unordered_map<address_ptr_t, registered_names_t>
 service address to registered names mapping type
Protected Types inherited from rotor::actor_base_t
using timers_map_t = std::unordered_map<request_id_t, timer_handler_ptr_t>
 timer-id to timer-handler map (type)
using requests_t = std::unordered_set<request_id_t>
 list of ids of active requests (type)

Protected Attributes

registered_map_t registered_map
 name-to-address mapping
reverse_map_t reverse_map
 address-to-list_of_names mapping
promises_list_t promises
 list of intrusive pointers to discovery promise messages
Protected Attributes inherited from rotor::actor_base_t
intrusive_ptr_t< message::init_request_tinit_request
 suspended init request message
intrusive_ptr_t< message::shutdown_request_tshutdown_request
 suspended shutdown request message
address_ptr_t address
 actor address
address_ptr_t spawner_address
 actor spawner address
std::string identity
 actor identity, which might have some meaning for developers
supervisor_tsupervisor
 non-owning pointer to actor's execution / infrastructure context
plugin_storage_ptr_t plugins_storage
 opaque plugins storage (owning)
plugins_t plugins
 non-owning list of plugins
pt::time_duration init_timeout
 timeout for actor initialization (used by supervisor)
pt::time_duration shutdown_timeout
 timeout for actor shutdown (used by supervisor)
state_t state
 current actor state
plugin::address_maker_plugin_taddress_maker = nullptr
 non-owning pointer to address_maker plugin
plugin::lifetime_plugin_tlifetime = nullptr
 non-owning pointer to lifetime plugin
plugin::link_server_plugin_tlink_server = nullptr
 non-owning pointer to link_server plugin
plugin::resources_plugin_tresources = nullptr
 non-owning pointer to resources plugin
std::set< const std::type_index * > activating_plugins
 set of activating plugin identities
std::set< const std::type_index * > deactivating_plugins
 set of deactivating plugin identities
timers_map_t timers_map
 timer-id to timer-handler map
requests_t active_requests
 list of ids of active requests
std::uint32_t continuation_mask = 0
 set of currently processing states, i.e. init or shutdown
extended_error_ptr_t shutdown_reason
 explanation, why actor is been requested for shut down

Additional Inherited Members

Public Types inherited from rotor::actor_base_t
using config_t = actor_config_t
 injects an alias for actor_config_t
template<typename Actor>
using config_builder_t = actor_config_builder_t<Actor>
 injects templated actor_config_builder_t
template<typename Handler>
using is_handler
 SFINAE handler detector.
using plugins_list_t
 the default list of plugins for an actor
Static Public Attributes inherited from rotor::actor_base_t
static const constexpr std::uint32_t PROGRESS_INIT = 1 << 0
 flag to mark, that actor is already executing initialization
static const constexpr std::uint32_t PROGRESS_SHUTDOWN = 1 << 1
 flag to mark, that actor is already executing shutdown
static const constexpr std::uint32_t ESCALATE_FALIURE = 1 << 2
 flag to mark, that actor is already executing shutdown
static const constexpr std::uint32_t AUTOSHUTDOWN_SUPERVISOR = 1 << 3
 flag to mark, that actor trigger supervisor shutdown
Protected Member Functions inherited from rotor::actor_base_t
void on_timer_trigger (request_id_t request_id, bool cancelled) noexcept
 triggers timer handler associated with the timer id
template<typename Delegate, typename Method>
void start_timer (request_id_t request_id, const pt::time_duration &interval, Delegate &delegate, Method method) noexcept
 starts timer with pre-forged timer id (aka request-id
void assign_shutdown_reason (extended_error_ptr_t reason) noexcept
 helper-method, which assigns shutdown reason if it isn't set
extended_error_ptr_t make_error (const std::error_code &ec, const extended_error_ptr_t &next={}, const message_ptr_t &request={}) const noexcept
 makes extended error within the context of the actor
virtual bool on_unlink (const address_ptr_t &server_addr) noexcept
 notification, when actor has been unlinked from server actor
plugin::plugin_base_tget_plugin (const std::type_index &) const noexcept
 finds plugin by plugin class identity

Detailed Description

keeps name-to-service_address mapping at runtime

The class solves the following problem: one actor needs to know somehow the address of other actor. Instead of tightly couple them, i.e. manually binding addresses, it is possible to just take the registry everywhere and ask it (or register there) just on actor startup (initialization)

The "server-actor" must register it's address first. The name must be unique (in the scope of registry); the same address can be registered on different names, if need. It is good practice to unregister addresses when actor is going to be shutdown (it is done by plugin::registry_plugin_t). It is possible to unregister single name, or all names associated with an address.

The discovery response returned to "client-actor" might contain error code if there is no address associated with the asked name.

The actor has syncronization facilities, i.e. it is possible to ask the actor to notify when some name has been registered (discovery promise/future).

Member Function Documentation

◆ actor_base_t()

rotor::actor_base_t::actor_base_t ( config_t & cfg)

constructs actor and links it's supervisor

An actor cannot outlive it's supervisor.

Sets internal actor state to NEW

◆ configure()

void rotor::registry_t::configure ( plugin::plugin_base_t & plugin)
overridevirtualnoexcept

main callback for plugin configuration when it's ready

Reimplemented from rotor::actor_base_t.


The documentation for this struct was generated from the following file:
  • /home/b/development/cpp/cpp-rotor/include/rotor/registry.h