libcaf  0.15.3
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::scheduled_actor caf::resumable caf::io::broker

Public Member Functions

void enqueue (mailbox_element_ptr, execution_unit *) override
 
void 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
 Resume any pending computation until it is either finished or needs to be re-scheduled later. More...
 
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 given connection. More...
 
void ack_writes (connection_handle hdl, bool enable)
 Enables or disables write notifications for given connection.
 
std::vector< char > & wr_buf (connection_handle hdl)
 Returns the write buffer for given connection.
 
void write (connection_handle hdl, size_t bs, const void *buf)
 Writes data into the buffer for given connection.
 
void flush (connection_handle hdl)
 Sends the content of the buffer for given connection.
 
middlemanparent ()
 Returns the middleman instance this broker belongs to.
 
void add_scribe (const intrusive_ptr< scribe > &ptr)
 Adds a scribe instance to this broker.
 
expected< connection_handleadd_tcp_scribe (const std::string &hostname, uint16_t port)
 Tries to connect to host on given port and creates a new scribe describing the connection afterwards. More...
 
expected< void > assign_tcp_scribe (connection_handle hdl)
 Assigns a detached scribe instance identified by hdl from the multiplexer to this broker. More...
 
expected< connection_handleadd_tcp_scribe (network::native_socket fd)
 Creates and assigns a new scribe from given native socked fd.
 
void add_doorman (const intrusive_ptr< doorman > &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. More...
 
expected< void > assign_tcp_doorman (accept_handle hdl)
 Assigns a detached doorman instance identified by hdl from the multiplexer to this broker. More...
 
expected< accept_handleadd_tcp_doorman (network::native_socket fd)
 Creates and assigns a new doorman from given native socked fd.
 
std::string remote_addr (connection_handle hdl)
 Returns the remote address associated to hdl or empty string if hdl is invalid. More...
 
uint16_t remote_port (connection_handle hdl)
 Returns the remote port associated to hdl or 0 if hdl is invalid. More...
 
std::string local_addr (accept_handle hdl)
 Returns the local address associated to hdl or empty string if hdl is invalid. More...
 
uint16_t local_port (accept_handle hdl)
 Returns the local port associated to hdl or 0 if hdl is invalid.
 
accept_handle hdl_by_port (uint16_t port)
 Returns the handle associated to given local port or none.
 
void close_all ()
 Closes all connections and acceptors.
 
template<class Handle >
bool close (Handle hdl)
 Closes the connection or acceptor identified by handle. More...
 
template<class Handle >
bool valid (Handle hdl)
 Checks whether hdl is assigned to broker.
 
const char * name () const override
 
subtype_t subtype () const override
 Returns a subtype hint for this object. More...
 
size_t num_connections () const
 Returns the number of open connections.
 
std::vector< connection_handleconnections () const
 Returns all handles of all scribe instances attached to this broker.
 
- Public Member Functions inherited from caf::scheduled_actor
 scheduled_actor (actor_config &cfg)
 
void enqueue (mailbox_element_ptr ptr, execution_unit *eu) override
 
const char * name () const override
 
void launch (execution_unit *eu, bool lazy, bool hide) override
 
bool cleanup (error &&fail_state, execution_unit *host) override
 
void intrusive_ptr_add_ref_impl () override
 Add a strong reference count to this object.
 
void intrusive_ptr_release_impl () override
 Remove a strong reference count from this object.
 
virtual proxy_registryproxy_registry_ptr ()
 Returns a factory for proxies created and managed by this actor or nullptr. More...
 
void quit (error x=error{})
 Finishes execution of this actor after any currently running message handler is done. More...
 
void set_default_handler (default_handler fun)
 Sets a custom handler for unexpected messages.
 
template<class F >
std::enable_if< std::is_convertible< F, std::function< result< message >type_erased_tuple &)> >::value >::type set_default_handler (F fun)
 Sets a custom handler for unexpected messages.
 
void set_error_handler (error_handler fun)
 Sets a custom handler for error messages.
 
template<class T >
auto set_error_handler (T fun) -> decltype(fun(std::declval< error & >()))
 Sets a custom handler for error messages.
 
void set_down_handler (down_handler fun)
 Sets a custom handler for down messages.
 
template<class T >
auto set_down_handler (T fun) -> decltype(fun(std::declval< down_msg & >()))
 Sets a custom handler for down messages.
 
void set_exit_handler (exit_handler fun)
 Sets a custom handler for error messages.
 
template<class T >
auto set_exit_handler (T fun) -> decltype(fun(std::declval< exit_msg & >()))
 Sets a custom handler for exit messages.
 
void set_exception_handler (exception_handler fun)
 Sets a custom exception handler for this actor. More...
 
template<class F >
std::enable_if< std::is_convertible< F, std::function< error(std::exception_ptr &)> >::value >::type set_exception_handler (F f)
 Sets a custom exception handler for this actor. More...
 

Protected Types

using doorman_map = std::unordered_map< accept_handle, intrusive_ptr< doorman >>
 
using scribe_map = std::unordered_map< connection_handle, intrusive_ptr< scribe >>
 

Protected Member Functions

void init_broker ()
 
 abstract_broker (actor_config &cfg)
 
network::multiplexerbackend ()
 Returns the multiplexer running this broker.
 
template<class Handle >
auto by_id (Handle hdl) -> optional< decltype(*ptr_of(hdl))>
 Returns a scribe or doorman identified by hdl.
 
template<class Handle >
auto take (Handle hdl) -> decltype(ptr_of(hdl))
 Returns an intrusive pointer to a scribe or doorman identified by hdl and remove it from this broker. More...
 

Friends

class scribe
 
class doorman
 

Additional Inherited Members

- Public Types inherited from caf::scheduled_actor
using pending_response = std::pair< const message_id, behavior >
 The message ID of an outstanding response with its callback.
 
using pointer = scheduled_actor *
 A pointer to a scheduled actor.
 
using default_handler = std::function< result< message >(pointer, message_view &)>
 Function object for handling unmatched messages.
 
using error_handler = std::function< void(pointer, error &)>
 Function object for handling error messages.
 
using down_handler = std::function< void(pointer, down_msg &)>
 Function object for handling down messages.
 
using exit_handler = std::function< void(pointer, exit_msg &)>
 Function object for handling exit messages.
 
using exception_handler = std::function< error(pointer, std::exception_ptr &)>
 Function object for handling exit messages.
 
- Public Types inherited from caf::resumable
enum  resume_result {
  resume_later,
  awaiting_message,
  done,
  shutdown_execution_unit
}
 Denotes the state in which a resumable returned from its last call to resume. More...
 
enum  subtype_t {
  unspecified,
  scheduled_actor,
  io_actor,
  function_object
}
 Denotes common subtypes of resumable. More...
 
- Static Public Member Functions inherited from caf::scheduled_actor
static void default_error_handler (pointer ptr, error &x)
 
static void default_down_handler (pointer ptr, down_msg &x)
 
static void default_exit_handler (pointer ptr, exit_msg &x)
 
static error default_exception_handler (pointer ptr, std::exception_ptr &x)
 

Detailed Description

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

Member Function Documentation

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.
expected<connection_handle> caf::io::abstract_broker::add_tcp_scribe ( const std::string &  hostname,
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.
expected<void> caf::io::abstract_broker::assign_tcp_doorman ( accept_handle  hdl)

Assigns a detached doorman instance identified by hdl from the multiplexer to this broker.

expected<void> caf::io::abstract_broker::assign_tcp_scribe ( connection_handle  hdl)

Assigns a detached scribe instance identified by hdl from the multiplexer to this broker.

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.

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

Modifies the receive policy for given connection.

Parameters
hdlIdentifies the affected connection.
cfgContains the new receive policy.
std::string caf::io::abstract_broker::local_addr ( accept_handle  hdl)

Returns the local address associated to hdl or empty string if hdl is invalid.

std::string caf::io::abstract_broker::remote_addr ( connection_handle  hdl)

Returns the remote address associated to hdl or empty string if hdl is invalid.

uint16_t caf::io::abstract_broker::remote_port ( connection_handle  hdl)

Returns the remote port associated to hdl or 0 if hdl is invalid.

resume_result caf::io::abstract_broker::resume ( execution_unit ,
size_t  max_throughput 
)
overridevirtual

Resume any pending computation until it is either finished or needs to be re-scheduled later.

Reimplemented from caf::scheduled_actor.

subtype_t caf::io::abstract_broker::subtype ( ) const
overridevirtual

Returns a subtype hint for this object.

This allows an execution unit to limit processing to a specific set of resumables and delegate other subtypes to dedicated workers.

Reimplemented from caf::scheduled_actor.

template<class Handle >
auto caf::io::abstract_broker::take ( Handle  hdl) -> decltype(ptr_of(hdl))
protected

Returns an intrusive pointer to a scribe or doorman identified by hdl and remove it from this broker.


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