rotor
Event loop friendly C++ actor micro-framework
 
Loading...
Searching...
No Matches
registry.h
1#pragma once
2//
3// Copyright (c) 2019-2020 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
4//
5// Distributed under the MIT Software License
6//
7
8#include "actor_base.h"
9#include "messages.hpp"
10#include <unordered_map>
11#include <set>
12#include <list>
13
14#if defined(_MSC_VER)
15#pragma warning(push)
16#pragma warning(disable : 4251)
17#endif
18
19namespace rotor {
20
46struct ROTOR_API registry_t : public actor_base_t {
47 using actor_base_t::actor_base_t;
48
49 void configure(plugin::plugin_base_t &plugin) noexcept override;
50
52 virtual void on_reg(message::registration_request_t &request) noexcept;
53
55 virtual void on_dereg_service(message::deregistration_service_t &message) noexcept;
56
58 virtual void on_dereg(message::deregistration_notify_t &message) noexcept;
59
61 virtual void on_discovery(message::discovery_request_t &request) noexcept;
62
64 virtual void on_promise(message::discovery_promise_t &request) noexcept;
65
67 virtual void on_cancel(message::discovery_cancel_t &notify) noexcept;
68
70 template <typename T> auto &access() noexcept;
71
72 protected:
74 using promise_ptr_t = intrusive_ptr_t<message::discovery_promise_t>;
75
77 using promises_list_t = std::list<promise_ptr_t>;
78
80 using registered_map_t = std::unordered_map<std::string, address_ptr_t>;
81
83 using registered_names_t = std::set<std::string>;
84
86 using reverse_map_t = std::unordered_map<address_ptr_t, registered_names_t>;
87
89 registered_map_t registered_map;
90
92 reverse_map_t reverse_map;
93
96};
97
98} // namespace rotor
99
100#if defined(_MSC_VER)
101#pragma warning(pop)
102#endif
Basic namespace for all rotor functionalities.
Definition rotor.hpp:21
intrusive_ptr_t< address_t > address_ptr_t
intrusive pointer for address
Definition address.hpp:57
boost::intrusive_ptr< T > intrusive_ptr_t
alias for intrusive pointer
Definition arc.hpp:27
universal primitive of concurrent computation
Definition actor_base.h:47
the generic message meant to hold user-specific payload
Definition message.h:83
base class for all actor plugins
Definition plugin_base.h:23
keeps name-to-service_address mapping at runtime
Definition registry.h:46
virtual void on_promise(message::discovery_promise_t &request) noexcept
notify the requestee when service name/address becomes available
intrusive_ptr_t< message::discovery_promise_t > promise_ptr_t
intrusive pointer to discovery promise message (type)
Definition registry.h:74
std::unordered_map< std::string, address_ptr_t > registered_map_t
name-to-address mapping type
Definition registry.h:80
virtual void on_cancel(message::discovery_cancel_t &notify) noexcept
cancels previously asked discovery promise
virtual void on_discovery(message::discovery_request_t &request) noexcept
returns service address associated with the name or error
virtual void on_reg(message::registration_request_t &request) noexcept
registers address on the service. Fails, if the name already exists
void configure(plugin::plugin_base_t &plugin) noexcept override
main callback for plugin configuration when it's ready
std::set< std::string > registered_names_t
set of registered names type (for single address)
Definition registry.h:83
auto & access() noexcept
generic non-public fields accessor
virtual void on_dereg_service(message::deregistration_service_t &message) noexcept
deregisters the name in the registry
std::list< promise_ptr_t > promises_list_t
list of intrusive pointers to discovery promise messages (type)
Definition registry.h:77
virtual void on_dereg(message::deregistration_notify_t &message) noexcept
deregisters all names associated with the service address
std::unordered_map< address_ptr_t, registered_names_t > reverse_map_t
service address to registered names mapping type
Definition registry.h:86