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

A broker mediates between actor systems and other components in the network. More...

#include <abstract_broker.hpp>

Inheritance diagram for caf::io::abstract_broker:
caf::io::broker caf::detail::prometheus_broker caf::io::basp_broker

Public Member Functions

 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.
 

Protected Types

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 > >
 

Protected Member Functions

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.
 

Friends

class scribe
 
class doorman
 
class datagram_servant
 

Detailed Description

A broker mediates between actor systems and other components in the network.

Member Function Documentation

◆ add_tcp_doorman()

expected< std::pair< accept_handle, uint16_t > > caf::io::abstract_broker::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.

If port == 0, then the broker will ask the operating system to pick a random port.

Returns
The handle of the new doorman and the assigned port.

◆ add_tcp_scribe()

expected< connection_handle > caf::io::abstract_broker::add_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.

Returns
The handle of the new scribe on success.

◆ add_udp_datagram_servant() [1/2]

expected< datagram_handle > caf::io::abstract_broker::add_udp_datagram_servant ( const std::string &  host,
uint16_t  port 
)

Creates a new datagram_servant for the remote endpoint host and port.

Returns
The handle to the new datagram_servant.

◆ add_udp_datagram_servant() [2/2]

expected< std::pair< datagram_handle, uint16_t > > caf::io::abstract_broker::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.

If port == 0, then the broker will ask the operating system to pick a random port.

Returns
The handle of the new datagram_servant and the assigned port.

◆ close()

template<class Handle >
bool caf::io::abstract_broker::close ( Handle  hdl)

Closes the connection or acceptor identified by handle.

Unwritten data will still be send.

◆ configure_read()

void caf::io::abstract_broker::configure_read ( connection_handle  hdl,
receive_policy::config  cfg 
)

Modifies the receive policy for a given connection.

Parameters
hdlIdentifies the affected connection.
cfgContains the new receive policy.

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