libcaf  0.15.0
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::module

Public Types

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,
  opencl_manager,
  riac_probe,
  num_ids
}
 

Public Member Functions

template<class Handle >
uint16_t publish (Handle &&whom, uint16_t port, const char *in=nullptr, bool reuse_addr=false)
 Publishes whom at port. More...
 
uint16_t publish_local_groups (uint16_t port, const char *addr=nullptr)
 Makes all local groups accessible via network on address addr and port. More...
 
template<class Handle >
void unpublish (const Handle &whom, uint16_t port=0)
 Unpublishes whom by closing port or all assigned ports if port == 0. More...
 
template<class ActorHandle >
ActorHandle typed_remote_actor (std::string host, uint16_t port)
 Establish a new connection to the typed actor at host on given port. More...
 
actor remote_actor (std::string host, uint16_t port)
 Establish a new connection to the actor at host on given port. More...
 
group remote_group (const std::string &group_uri)
 <group-name><host>:<port>
 
group remote_group (const std::string &group_identifier, const std::string &host, uint16_t port)
 
actor_system & system ()
 Returns the enclosing actor system.
 
middleman_actor actor_handle ()
 Returns a handle to the actor managing the middleman singleton.
 
template<class Impl >
actor named_broker (atom_value name)
 Returns the broker associated with name or creates a new instance of type Impl. More...
 
template<class F >
void run_later (F fun)
 Runs fun in the event loop of the middleman. More...
 
virtual network::multiplexerbackend ()=0
 Returns the IO backend used by this middleman.
 
template<hook::event_type Event, typename... Ts>
void notify (Ts &&...ts)
 Invokes the callback(s) associated with given event.
 
template<class C , typename... Ts>
C * add_hook (Ts &&...xs)
 Adds a new hook to the middleman.
 
bool has_hook () const
 Returns whether this middleman has any hooks installed.
 
template<class F >
void add_shutdown_cb (F fun)
 Adds a function object to this middleman that is called when shutting down this middleman. More...
 
strong_actor_ptr remote_lookup (atom_value 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. More...
 
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. More...
 
id_t id () const override
 Returns the identifier of this module.
 
void * subtype_ptr () override
 Returns a pointer to the subtype.
 
template<spawn_options Os = no_spawn_options, class F = std::function<void(broker*)>, class... Ts>
infer_handle_from_fun< F >::type 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>
infer_handle_from_fun< F >::type spawn_client (F fun, const std::string &host, uint16_t port, Ts &&...xs)
 Returns a new functor-based broker connected to host:port if a connection succeeds or the occurred error. More...
 
template<spawn_options Os = no_spawn_options, class F = std::function<void(broker*)>, class... Ts>
infer_handle_from_fun< F >::type spawn_server (F fun, uint16_t port, Ts &&...xs)
 Spawns a new broker as server running on given port. More...
 
size_t heartbeat_interval () const
 Returns the heartbeat interval in milliseconds.
 
bool enable_automatic_connections () const
 Returns whether the middleman tries to establish a direct connection to each of its peers. More...
 

Static Public Member Functions

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 &ref)
 

Friends

class actor_system
 

Detailed Description

Manages brokers and network backends.

Member Function Documentation

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

Adds a function object to this middleman that is called when shutting down this middleman.

bool caf::io::middleman::enable_automatic_connections ( ) const

Returns whether the middleman tries to establish a direct connection to each of its peers.

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.

template<class Impl >
actor caf::io::middleman::named_broker ( atom_value  name)

Returns the broker associated with name or creates a new instance of type Impl.

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

Publishes whom at port.

Parameters
whomActor that should be published at port.
portUnused TCP port.
inThe IP address to listen to or INADDR_ANY if in == nullptr.
Returns
The actual port the OS uses after bind(). If port == 0 the OS chooses a random high-level port.
uint16_t caf::io::middleman::publish_local_groups ( uint16_t  port,
const char *  addr = nullptr 
)

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.
actor 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_ptr to the proxy instance representing a remote actor.
Exceptions
network_errorThrown on connection error or when connecting to a typed actor.
strong_actor_ptr caf::io::middleman::remote_lookup ( atom_value  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.

Warning
Blocks the caller until nid responded to the lookup.
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.
template<spawn_options Os = no_spawn_options, class F = std::function<void(broker*)>, class... Ts>
infer_handle_from_fun<F>::type 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 if a connection succeeds or the occurred error.

Warning
Blocks the caller for the duration of the connection process.
template<spawn_options Os = no_spawn_options, class F = std::function<void(broker*)>, class... Ts>
infer_handle_from_fun<F>::type 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.
template<class ActorHandle >
ActorHandle caf::io::middleman::typed_remote_actor ( std::string  host,
uint16_t  port 
)

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

Parameters
hostValid hostname or IP address.
portTCP port.
Returns
An actor_ptr to the proxy instance representing a typed remote actor.
Exceptions
network_errorThrown on connection error or when connecting to an untyped otherwise unexpected actor.
template<class Handle >
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 file: