C++ Actor Framework 0.19
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
caf::io::middleman Class Referenceabstract

Manages brokers and network backends. More...

#include <middleman.hpp>

Inheritance diagram for caf::io::middleman:
caf::actor_system::networking_module caf::actor_system::module

Classes

struct  background_task
 Independent tasks that run in the background, usually in their own thread. More...
 
struct  metric_singletons_t
 Metrics that the middleman collects by default. More...
 

Public Types

using background_task_ptr = std::unique_ptr< background_task >
 
using backend_pointer = std::unique_ptr< network::multiplexer >
 Smart pointer for network::multiplexer.
 
using backend_factory = std::function< backend_pointer()>
 Used to initialize the backend during construction.
 
- Public Types inherited from caf::actor_system::module
enum  id_t {
  scheduler ,
  middleman ,
  openssl_manager ,
  network_manager ,
  num_ids
}
 

Public Member Functions

expected< uint16_t > open (uint16_t port, const char *in=nullptr, bool reuse=false)
 Tries to open a port for other CAF instances to connect to.
 
expected< void > close (uint16_t port)
 Closes port port regardless of whether an actor is published to it.
 
expected< node_idconnect (std::string host, uint16_t port)
 Tries to connect to given node.
 
template<class Handle >
expected< uint16_t > publish (Handle &&whom, uint16_t port, const char *in=nullptr, bool reuse=false)
 Tries to publish whom at port and returns either an error or the bound port.
 
expected< uint16_t > publish_local_groups (uint16_t port, const char *in=nullptr, bool reuse=false)
 Makes all local groups accessible via network on address addr and port.
 
template<class Handle >
expected< void > unpublish (const Handle &whom, uint16_t port=0)
 Unpublishes whom by closing port or all assigned ports if port == 0.
 
template<class ActorHandle = actor>
expected< ActorHandle > remote_actor (std::string host, uint16_t port)
 Establish a new connection to the actor at host on given port.
 
expected< group > remote_group (const std::string &group_locator)
 Tries to connect to a group that runs on a different node in the network.
 
expected< group > remote_group (const std::string &group_identifier, const std::string &host, uint16_t port)
 Tries to connect to a group that runs on a different node in the network.
 
actor_systemsystem ()
 Returns the enclosing actor system.
 
const actor_system_configconfig () const
 Returns the systemw-wide configuration.
 
middleman_actor actor_handle ()
 Returns a handle to the actor managing the middleman singleton.
 
template<class Impl >
actor named_broker (const std::string &name)
 Returns the broker associated with name or creates a new instance of type Impl.
 
template<class F >
void run_later (F fun)
 Runs fun in the event loop of the middleman.
 
virtual network::multiplexerbackend ()=0
 Returns the IO backend used by this middleman.
 
strong_actor_ptr remote_lookup (std::string name, const node_id &nid)
 Returns the actor associated with name at nid or invalid_actor if nid is not connected or has no actor associated to this name.
 
template<class Handle >
expected< Handle > remote_spawn (const node_id &nid, std::string name, message args, timespan timeout=timespan{std::chrono::minutes{1}})
 
template<class Handle , class Rep , class Period >
expected< Handle > remote_spawn (const node_id &nid, std::string name, message args, std::chrono::duration< Rep, Period > timeout)
 
void start () override
 Starts any background threads needed by the module.
 
void stop () override
 Stops all background threads of the module.
 
void init (actor_system_config &) override
 Allows the module to change the configuration of the actor system during startup.
 
id_t id () const override
 Returns the identifier of this module.
 
void * subtype_ptr () override
 Returns a pointer to the subtype.
 
void monitor (const node_id &node, const actor_addr &observer) override
 Causes the module to send a node_down_msg to observer if this system loses connection to node.
 
void demonitor (const node_id &node, const actor_addr &observer) override
 Causes the module remove one entry for observer from the list of actors that receive a node_down_msg if this system loses connection to node.
 
template<spawn_options Os = no_spawn_options, class F = std::function<void(broker*)>, class... Ts>
infer_handle_from_fun_t< F > spawn_broker (F fun, Ts &&... xs)
 Spawns a new functor-based broker.
 
template<spawn_options Os = no_spawn_options, class F = std::function<void(broker*)>, class... Ts>
expected< infer_handle_from_fun_t< F > > spawn_client (F fun, const std::string &host, uint16_t port, Ts &&... xs)
 Returns a new functor-based broker connected to host:port or an error.
 
template<spawn_options Os = no_spawn_options, class F = std::function<void(broker*)>, class... Ts>
expected< infer_handle_from_fun_t< F > > spawn_server (F fun, uint16_t &port, Ts &&... xs)
 Spawns a new broker as server running on given port.
 
template<spawn_options Os = no_spawn_options, class F = std::function<void(broker*)>, class... Ts>
expected< infer_handle_from_fun_t< F > > spawn_server (F fun, const uint16_t &port, Ts &&... xs)
 Spawns a new broker as server running on given port.
 
virtual void monitor (const node_id &node, const actor_addr &observer)=0
 Causes the module to send a node_down_msg to observer if this system loses connection to node.
 
virtual void demonitor (const node_id &node, const actor_addr &observer)=0
 Causes the module remove one entry for observer from the list of actors that receive a node_down_msg if this system loses connection to node.
 
- Public Member Functions inherited from caf::actor_system::module
const char * name () const noexcept
 Returns the human-readable name of the module.
 
virtual void start ()=0
 Starts any background threads needed by the module.
 
virtual void stop ()=0
 Stops all background threads of the module.
 
virtual void init (actor_system_config &)=0
 Allows the module to change the configuration of the actor system during startup.
 
virtual id_t id () const =0
 Returns the identifier of this module.
 
virtual void * subtype_ptr ()=0
 Returns a pointer to the subtype.
 

Static Public Member Functions

static void init_global_meta_objects ()
 Adds message types of the I/O module to the global meta object table.
 
static void add_module_options (actor_system_config &cfg)
 Adds module-specific options to the config before loading the module.
 
static actor_system::modulemake (actor_system &, detail::type_list<>)
 Returns a middleman using the default network backend.
 
template<class Backend >
static actor_system::modulemake (actor_system &sys, detail::type_list< Backend >)
 

Protected Member Functions

 middleman (actor_system &sys)
 

Friends

class actor_system
 

Detailed Description

Manages brokers and network backends.

Member Function Documentation

◆ demonitor()

void caf::io::middleman::demonitor ( const node_id node,
const actor_addr observer 
)
overridevirtual

Causes the module remove one entry for observer from the list of actors that receive a node_down_msg if this system loses connection to node.

Each call to monitor requires one call to demonitor in order to unsubscribe the observer completely.

Implements caf::actor_system::networking_module.

◆ id()

actor_system::module::id_t caf::io::middleman::id ( ) const
overridevirtual

Returns the identifier of this module.

Implements caf::actor_system::module.

◆ init()

void caf::io::middleman::init ( actor_system_config )
overridevirtual

Allows the module to change the configuration of the actor system during startup.

Implements caf::actor_system::module.

◆ monitor()

void caf::io::middleman::monitor ( const node_id node,
const actor_addr observer 
)
overridevirtual

Causes the module to send a node_down_msg to observer if this system loses connection to node.

Implements caf::actor_system::networking_module.

◆ publish()

template<class Handle >
expected< uint16_t > caf::io::middleman::publish ( Handle &&  whom,
uint16_t  port,
const char *  in = nullptr,
bool  reuse = false 
)

Tries to publish whom at port and returns either an error or the bound port.

Parameters
whomActor that should be published at port.
portUnused TCP port.
inThe IP address to listen to or INADDR_ANY if in == nullptr.
reuseCreate socket using SO_REUSEADDR.
Returns
The actual port the OS uses after bind(). If port == 0 the OS chooses a random high-level port.

◆ publish_local_groups()

expected< uint16_t > caf::io::middleman::publish_local_groups ( uint16_t  port,
const char *  in = nullptr,
bool  reuse = false 
)

Makes all local groups accessible via network on address addr and port.

Returns
The actual port the OS uses after bind(). If port == 0 the OS chooses a random high-level port.

◆ remote_actor()

template<class ActorHandle = actor>
expected< ActorHandle > caf::io::middleman::remote_actor ( std::string  host,
uint16_t  port 
)

Establish a new connection to the actor at host on given port.

Parameters
hostValid hostname or IP address.
portTCP port.
Returns
An actor to the proxy instance representing a remote actor or an error.

◆ remote_group() [1/2]

expected< group > caf::io::middleman::remote_group ( const std::string &  group_identifier,
const std::string &  host,
uint16_t  port 
)

Tries to connect to a group that runs on a different node in the network.

Parameters
group_identifierUnique identifier of the group.
hostHostname or IP address of the remote CAF node.
portTCP port for connecting to the group name server of the node.

We won't receive a second message, so we drop our behavior here to terminate the actor after both requests finish.

◆ remote_group() [2/2]

expected< group > caf::io::middleman::remote_group ( const std::string &  group_locator)

Tries to connect to a group that runs on a different node in the network.

Parameters
group_locatorLocator in the format <group-name>@<host>:<port>.

◆ remote_lookup()

strong_actor_ptr caf::io::middleman::remote_lookup ( std::string  name,
const node_id nid 
)

Returns the actor associated with name at nid or invalid_actor if nid is not connected or has no actor associated to this name.

Note
Blocks the caller until nid responded to the lookup or an error occurred.

◆ run_later()

template<class F >
void caf::io::middleman::run_later ( fun)

Runs fun in the event loop of the middleman.

Note
This member function is thread-safe.

◆ spawn_client()

template<spawn_options Os = no_spawn_options, class F = std::function<void(broker*)>, class... Ts>
expected< infer_handle_from_fun_t< F > > caf::io::middleman::spawn_client ( fun,
const std::string &  host,
uint16_t  port,
Ts &&...  xs 
)

Returns a new functor-based broker connected to host:port or an error.

Warning
Blocks the caller for the timespan of the connection process.

◆ spawn_server() [1/2]

template<spawn_options Os = no_spawn_options, class F = std::function<void(broker*)>, class... Ts>
expected< infer_handle_from_fun_t< F > > caf::io::middleman::spawn_server ( fun,
const uint16_t &  port,
Ts &&...  xs 
)

Spawns a new broker as server running on given port.

Warning
Blocks the caller until the server socket is initialized.

◆ spawn_server() [2/2]

template<spawn_options Os = no_spawn_options, class F = std::function<void(broker*)>, class... Ts>
expected< infer_handle_from_fun_t< F > > caf::io::middleman::spawn_server ( fun,
uint16_t &  port,
Ts &&...  xs 
)

Spawns a new broker as server running on given port.

Warning
Blocks the caller until the server socket is initialized.

◆ start()

void caf::io::middleman::start ( )
overridevirtual

Starts any background threads needed by the module.

Implements caf::actor_system::module.

◆ stop()

void caf::io::middleman::stop ( )
overridevirtual

Stops all background threads of the module.

Implements caf::actor_system::module.

◆ subtype_ptr()

void * caf::io::middleman::subtype_ptr ( )
overridevirtual

Returns a pointer to the subtype.

Implements caf::actor_system::module.

◆ unpublish()

template<class Handle >
expected< void > caf::io::middleman::unpublish ( const Handle &  whom,
uint16_t  port = 0 
)

Unpublishes whom by closing port or all assigned ports if port == 0.

Parameters
whomActor that should be unpublished at port.
portTCP port.

The documentation for this class was generated from the following files: