C++ Actor Framework 0.18
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | List of all members
caf::io::basp_broker Class Reference

A broker implementation for the Binary Actor System Protocol (BASP). More...

#include <basp_broker.hpp>

Inheritance diagram for caf::io::basp_broker:
caf::io::broker caf::proxy_registry::backend caf::io::basp::instance::callee caf::io::abstract_broker caf::dynamically_typed_actor_base

Public Types

using super = broker
 
using ctx_map = std::unordered_map< connection_handle, basp::endpoint_context >
 
using monitored_actor_map = std::unordered_map< actor_addr, std::unordered_set< node_id > >
 
- Public Types inherited from caf::io::broker
using super = extend< abstract_broker, broker >::with< mixin::sender, mixin::requester, mixin::behavior_changer >
 
using signatures = none_t
 

Public Member Functions

 basp_broker (actor_config &cfg)
 
void on_exit () override
 
const char * name () const override
 
behavior make_behavior () override
 
proxy_registryproxy_registry_ptr () override
 
resume_result resume (execution_unit *, size_t) override
 
strong_actor_ptr make_proxy (node_id nid, actor_id aid) override
 Creates a new proxy instance.
 
void set_last_hop (node_id *ptr) override
 Sets the thread-local last-hop pointer to detect indirect connections.
 
void finalize_handshake (const node_id &nid, actor_id aid, std::set< std::string > &sigs) override
 Called if a server handshake was received and the connection to nid is established.
 
void purge_state (const node_id &nid) override
 Called whenever a direct connection was closed or a node became unreachable for other reasons before this node gets erased from the routing table.
 
void proxy_announced (const node_id &nid, actor_id aid) override
 Called whenever a remote node created a proxy for one of our local actors.
 
void learned_new_node_directly (const node_id &nid, bool was_indirectly_before) override
 Called whenever BASP learns the ID of a remote node to which it does not have a direct connection.
 
void learned_new_node_indirectly (const node_id &nid) override
 Called whenever BASP learns the ID of a remote node to which it does not have a direct connection.
 
byte_bufferget_buffer (connection_handle hdl) override
 Returns a reference to the sent buffer.
 
void flush (connection_handle hdl) override
 Flushes the underlying write buffer of hdl.
 
void handle_heartbeat () override
 Called if a heartbeat was received from nid
 
execution_unitcurrent_execution_unit () override
 Returns the current CAF scheduler context.
 
strong_actor_ptr this_actor () override
 Returns a handle to the callee actor.
 
void emit_node_down_msg (const node_id &node, const error &reason)
 Sends node_down_msg to all registered observers.
 
void learned_new_node (const node_id &nid)
 Performs bookkeeping such as managing spawn_servers.
 
void set_context (connection_handle hdl)
 Sets this_context by either creating or accessing state for hdl.
 
void connection_cleanup (connection_handle hdl, sec code)
 Cleans up any state for hdl.
 
void send_basp_down_message (const node_id &nid, actor_id aid, error err)
 Sends a basp::down_message message to a remote node.
 
void handle_down_msg (down_msg &)
 
actor_systemsystem ()
 
const actor_system_configconfig ()
 
const node_idthis_node () const
 Returns the node identifier of the underlying BASP instance.
 
- Public Member Functions inherited from caf::io::broker
template<class F , class... Ts>
infer_handle_from_fun< F >::type fork (F fun, connection_handle hdl, Ts &&... xs)
 
void initialize () override
 
 broker (actor_config &cfg)
 
 broker (broker &&)=delete
 
 broker (const broker &)=delete
 
brokeroperator= (broker &&)=delete
 
brokeroperator= (const broker &)=delete
 
- Public Member Functions inherited from caf::io::abstract_broker
 abstract_broker (abstract_broker &&)=delete
 
 abstract_broker (const abstract_broker &&)=delete
 
abstract_brokeroperator= (abstract_broker &&)=delete
 
abstract_brokeroperator= (const abstract_broker &&)=delete
 
bool enqueue (mailbox_element_ptr, execution_unit *) override
 
bool enqueue (strong_actor_ptr, message_id, message, execution_unit *) override
 
void launch (execution_unit *eu, bool lazy, bool hide) override
 
bool cleanup (error &&reason, execution_unit *host) override
 
resume_result resume (execution_unit *, size_t) override
 
template<class Handle >
void halt (Handle hdl)
 Suspends activities on hdl unconditionally.
 
template<class Handle >
void trigger (Handle hdl)
 Allows activities on hdl unconditionally (default).
 
template<class Handle >
void trigger (Handle hdl, size_t num_events)
 Allows num_events activities on hdl.
 
void configure_read (connection_handle hdl, receive_policy::config cfg)
 Modifies the receive policy for a given connection.
 
void ack_writes (connection_handle hdl, bool enable)
 Enables or disables write notifications for a given connection.
 
byte_bufferwr_buf (connection_handle hdl)
 Returns the write buffer for a given connection.
 
void write (connection_handle hdl, size_t bs, const void *buf)
 Writes data into the buffer for a given connection.
 
void write (connection_handle hdl, span< const byte > buf)
 Writes buf into the buffer for a given connection.
 
void flush (connection_handle hdl)
 Sends the content of the buffer for a given connection.
 
void ack_writes (datagram_handle hdl, bool enable)
 Enables or disables write notifications for a given datagram socket.
 
byte_bufferwr_buf (datagram_handle hdl)
 Returns the write buffer for a given sink.
 
void enqueue_datagram (datagram_handle, byte_buffer)
 Enqueue a buffer to be sent as a datagram via a given endpoint.
 
void write (datagram_handle hdl, size_t data_size, const void *data)
 Writes data into the buffer of a given sink.
 
void flush (datagram_handle hdl)
 Sends the content of the buffer to a UDP endpoint.
 
middlemanparent ()
 Returns the middleman instance this broker belongs to.
 
void add_scribe (scribe_ptr ptr)
 Adds the uninitialized scribe instance ptr to this broker.
 
connection_handle add_scribe (network::native_socket fd)
 Creates and assigns a new scribe from given native socked fd.
 
expected< connection_handleadd_tcp_scribe (const std::string &host, uint16_t port)
 Tries to connect to host on given port and creates a new scribe describing the connection afterwards.
 
void move_scribe (scribe_ptr ptr)
 Moves the initialized scribe instance ptr from another broker to this broker.
 
void add_doorman (doorman_ptr ptr)
 Adds a doorman instance to this broker.
 
accept_handle add_doorman (network::native_socket fd)
 Creates and assigns a new doorman from given native socked fd.
 
void move_doorman (doorman_ptr ptr)
 Adds a doorman instance to this broker.
 
expected< std::pair< accept_handle, uint16_t > > add_tcp_doorman (uint16_t port=0, const char *in=nullptr, bool reuse_addr=false)
 Tries to open a local port and creates a doorman managing it on success.
 
void add_datagram_servant (datagram_servant_ptr ptr)
 Adds a datagram_servant to this broker.
 
void add_hdl_for_datagram_servant (datagram_servant_ptr ptr, datagram_handle hdl)
 Adds the datagram_servant under an additional hdl.
 
datagram_handle add_datagram_servant (network::native_socket fd)
 Creates and assigns a new datagram_servant from a given socket fd.
 
datagram_handle add_datagram_servant_for_endpoint (network::native_socket fd, const network::ip_endpoint &ep)
 Creates and assigns a new datagram_servant from a given socket fd for the remote endpoint ep.
 
expected< datagram_handleadd_udp_datagram_servant (const std::string &host, uint16_t port)
 Creates a new datagram_servant for the remote endpoint host and port.
 
expected< std::pair< datagram_handle, uint16_t > > add_udp_datagram_servant (uint16_t port=0, const char *in=nullptr, bool reuse_addr=false)
 Tries to open a local port and creates a datagram_servant managing it on success.
 
void move_datagram_servant (datagram_servant_ptr ptr)
 Moves an initialized datagram_servant instance ptr from another broker to this one.
 
std::string remote_addr (connection_handle hdl)
 Returns the remote address associated with hdl or empty string if hdl is invalid.
 
uint16_t remote_port (connection_handle hdl)
 Returns the remote port associated with hdl or 0 if hdl is invalid.
 
std::string local_addr (accept_handle hdl)
 Returns the local address associated with hdl or empty string if hdl is invalid.
 
uint16_t local_port (accept_handle hdl)
 Returns the local port associated with hdl or 0 if hdl is invalid.
 
accept_handle hdl_by_port (uint16_t port)
 Returns the handle associated with given local port or none.
 
datagram_handle datagram_hdl_by_port (uint16_t port)
 Returns the dgram handle associated with given local port or none.
 
std::string remote_addr (datagram_handle hdl)
 Returns the remote address associated with hdl or an empty string if hdl is invalid.
 
uint16_t remote_port (datagram_handle hdl)
 Returns the remote port associated with hdl or 0 if hdl is invalid.
 
uint16_t local_port (datagram_handle hdl)
 Returns the remote port associated with hdl or 0 if hdl is invalid.
 
bool remove_endpoint (datagram_handle hdl)
 Remove the endpoint hdl from the broker.
 
void close_all ()
 Closes all connections and acceptors.
 
template<class Handle >
bool close (Handle hdl)
 Closes the connection or acceptor identified by handle.
 
template<class Handle >
bool valid (Handle hdl)
 Checks whether hdl is assigned to broker.
 
const char * name () const override
 
subtype_t subtype () const override
 
size_t num_connections () const noexcept
 Returns the number of open connections.
 
size_t num_doormen () const noexcept
 Returns the number of attached doorman for accepting incoming connections.
 
std::vector< connection_handleconnections () const
 Returns all handles of all scribe instances attached to this broker.
 
network::multiplexerbackend ()
 Returns the multiplexer running this broker.
 
virtual strong_actor_ptr make_proxy (node_id, actor_id)=0
 Creates a new proxy instance.
 
virtual void set_last_hop (node_id *ptr)=0
 Sets the thread-local last-hop pointer to detect indirect connections.
 
- Public Member Functions inherited from caf::io::basp::instance::callee
 callee (actor_system &sys, proxy_registry::backend &backend)
 
virtual void finalize_handshake (const node_id &nid, actor_id aid, std::set< std::string > &sigs)=0
 Called if a server handshake was received and the connection to nid is established.
 
virtual void purge_state (const node_id &nid)=0
 Called whenever a direct connection was closed or a node became unreachable for other reasons before this node gets erased from the routing table.
 
virtual void proxy_announced (const node_id &nid, actor_id aid)=0
 Called whenever a remote node created a proxy for one of our local actors.
 
virtual void learned_new_node_directly (const node_id &nid, bool was_known_indirectly)=0
 Called whenever BASP learns the ID of a remote node to which it does not have a direct connection.
 
virtual void learned_new_node_indirectly (const node_id &nid)=0
 Called whenever BASP learns the ID of a remote node to which it does not have a direct connection.
 
virtual void handle_heartbeat ()=0
 Called if a heartbeat was received from nid
 
virtual execution_unitcurrent_execution_unit ()=0
 Returns the current CAF scheduler context.
 
proxy_registryproxies ()
 Returns the actor namespace associated to this BASP protocol instance.
 
virtual byte_bufferget_buffer (connection_handle hdl)=0
 Returns a reference to the sent buffer.
 
virtual void flush (connection_handle hdl)=0
 Flushes the underlying write buffer of hdl.
 
virtual strong_actor_ptr this_actor ()=0
 Returns a handle to the callee actor.
 

Public Attributes

union {
   basp::instance   instance
 
}; 
 Protocol instance of BASP.
 
ctx_map ctx
 Keeps context information for all open connections.
 
basp::endpoint_context * this_context
 points to the current context for callbacks.
 
std::unordered_map< node_id, actorspawn_servers
 Stores handles to spawn servers for other nodes.
 
std::unordered_map< node_id, std::vector< actor_addr > > node_observers
 Keeps track of actors that wish to receive a node_down_msg if a particular node fails.
 
bool automatic_connections = false
 Configures whether BASP automatically open new connections to optimize routing paths by forming a mesh between all nodes.
 
monitored_actor_map monitored_actors
 Keeps track of nodes that monitor local actors.
 

Additional Inherited Members

- Protected Types inherited from caf::io::abstract_broker
using doorman_map = std::unordered_map< accept_handle, intrusive_ptr< doorman > >
 
using scribe_map = std::unordered_map< connection_handle, intrusive_ptr< scribe > >
 
using datagram_servant_map = std::unordered_map< datagram_handle, intrusive_ptr< datagram_servant > >
 
virtual behavior make_behavior ()
 
- Protected Member Functions inherited from caf::io::abstract_broker
void init_broker ()
 
 abstract_broker (actor_config &cfg)
 
template<class Handle >
auto by_id (Handle hdl) -> optional< decltype(*ptr_of(hdl))>
 Returns a scribe or doorman identified by hdl.
 
- Protected Attributes inherited from caf::io::basp::instance::callee
proxy_registry namespace_
 

Detailed Description

A broker implementation for the Binary Actor System Protocol (BASP).

Member Function Documentation

◆ current_execution_unit()

execution_unit * caf::io::basp_broker::current_execution_unit ( )
overridevirtual

Returns the current CAF scheduler context.

Implements caf::io::basp::instance::callee.

◆ finalize_handshake()

void caf::io::basp_broker::finalize_handshake ( const node_id nid,
actor_id  aid,
std::set< std::string > &  sigs 
)
overridevirtual

Called if a server handshake was received and the connection to nid is established.

Implements caf::io::basp::instance::callee.

◆ flush()

void caf::io::basp_broker::flush ( connection_handle  hdl)
overridevirtual

Flushes the underlying write buffer of hdl.

Implements caf::io::basp::instance::callee.

◆ get_buffer()

byte_buffer & caf::io::basp_broker::get_buffer ( connection_handle  hdl)
overridevirtual

Returns a reference to the sent buffer.

Implements caf::io::basp::instance::callee.

◆ handle_heartbeat()

void caf::io::basp_broker::handle_heartbeat ( )
overridevirtual

Called if a heartbeat was received from nid

Implements caf::io::basp::instance::callee.

◆ learned_new_node_directly()

void caf::io::basp_broker::learned_new_node_directly ( const node_id nid,
bool  was_known_indirectly 
)
overridevirtual

Called whenever BASP learns the ID of a remote node to which it does not have a direct connection.

Implements caf::io::basp::instance::callee.

◆ learned_new_node_indirectly()

void caf::io::basp_broker::learned_new_node_indirectly ( const node_id nid)
overridevirtual

Called whenever BASP learns the ID of a remote node to which it does not have a direct connection.

Implements caf::io::basp::instance::callee.

◆ make_behavior()

behavior caf::io::basp_broker::make_behavior ( )
overridevirtual

Reimplemented from caf::io::broker.

◆ make_proxy()

strong_actor_ptr caf::io::basp_broker::make_proxy ( node_id  ,
actor_id   
)
overridevirtual

Creates a new proxy instance.

Implements caf::proxy_registry::backend.

◆ proxy_announced()

void caf::io::basp_broker::proxy_announced ( const node_id nid,
actor_id  aid 
)
overridevirtual

Called whenever a remote node created a proxy for one of our local actors.

Implements caf::io::basp::instance::callee.

◆ purge_state()

void caf::io::basp_broker::purge_state ( const node_id nid)
overridevirtual

Called whenever a direct connection was closed or a node became unreachable for other reasons before this node gets erased from the routing table.

Warning
The implementing class must not modify the routing table from this callback.

Implements caf::io::basp::instance::callee.

◆ set_context()

void caf::io::basp_broker::set_context ( connection_handle  hdl)

Sets this_context by either creating or accessing state for hdl.

Automatically sets endpoint_context::last_seen to clock().now().

◆ set_last_hop()

void caf::io::basp_broker::set_last_hop ( node_id ptr)
overridevirtual

Sets the thread-local last-hop pointer to detect indirect connections.

Implements caf::proxy_registry::backend.

◆ this_actor()

strong_actor_ptr caf::io::basp_broker::this_actor ( )
overridevirtual

Returns a handle to the callee actor.

Implements caf::io::basp::instance::callee.

Member Data Documentation

◆ spawn_servers

std::unordered_map<node_id, actor> caf::io::basp_broker::spawn_servers

Stores handles to spawn servers for other nodes.

These servers are spawned whenever the broker learns a new node ID and tries to get a 'SpawnServ' instance on the remote side.


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