libcaf  0.14.4
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::local_actor caf::abstract_actor caf::resumable caf::abstract_channel caf::ref_counted caf::memory_managed caf::io::broker

Public Member Functions

void enqueue (const actor_addr &, message_id, message, execution_unit *) override
 Enqueues a new message to the channel.
 
void enqueue (mailbox_element_ptr, execution_unit *) override
 Enqueues a new message wrapped in a mailbox_element to the channel. More...
 
void cleanup (uint32_t reason) override
 Called after this broker has finished execution.
 
void launch (execution_unit *eu, bool lazy, bool hide)
 Starts running this broker in the middleman.
 
void configure_read (connection_handle hdl, receive_policy::config config)
 Modifies the receive policy for given connection. More...
 
std::vector< char > & wr_buf (connection_handle hdl)
 Returns the write buffer for given connection.
 
void write (connection_handle hdl, size_t data_size, const void *data)
 Writes data into the buffer for given connection.
 
void flush (connection_handle hdl)
 Sends the content of the buffer for given connection.
 
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.
 
middlemanparent ()
 Returns the middleman instance this broker belongs to.
 
void add_scribe (const intrusive_ptr< scribe > &ptr)
 Adds a scribe instance to this broker.
 
connection_handle 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. More...
 
void assign_tcp_scribe (connection_handle hdl)
 Assigns a detached scribe instance identified by hdl from the multiplexer to this broker. More...
 
connection_handle add_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.
 
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...
 
void assign_tcp_doorman (accept_handle hdl)
 Assigns a detached doorman instance identified by hdl from the multiplexer to this broker. More...
 
accept_handle add_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.
 
maybe< accept_handlehdl_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 >
void 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
 Returns an implementation-dependent name for logging purposes, which is only valid as long as the actor is running. More...
 
- Public Member Functions inherited from caf::local_actor
template<class T , spawn_options Os = no_spawn_options, class... Ts>
infer_handle_from_class< T >::type spawn (Ts &&...xs)
 
template<spawn_options Os = no_spawn_options, class F , class... Ts>
infer_handle_from_fun< F >::type spawn (F fun, Ts &&...xs)
 
template<class T , spawn_options Os = no_spawn_options, class Groups , class... Ts>
actor spawn_in_groups (const Groups &grps, Ts &&...xs)
 
template<class T , spawn_options Os = no_spawn_options, class... Ts>
actor spawn_in_groups (std::initializer_list< group > grps, Ts &&...xs)
 
template<class T , spawn_options Os = no_spawn_options, class... Ts>
actor spawn_in_group (const group &grp, Ts &&...xs)
 
template<spawn_options Os = no_spawn_options, class Groups , class... Ts>
actor spawn_in_groups (const Groups &grps, Ts &&...xs)
 
template<spawn_options Os = no_spawn_options, class... Ts>
actor spawn_in_groups (std::initializer_list< group > grps, Ts &&...xs)
 
template<spawn_options Os = no_spawn_options, class... Ts>
actor spawn_in_group (const group &grp, Ts &&...xs)
 
template<class T , spawn_options Os = no_spawn_options, class... Ts>
CAF_DEPRECATED actor_handle_from_signature_list< typename T::signatures >::type spawn_typed (Ts &&...xs)
 
template<spawn_options Os = no_spawn_options, typename F , class... Ts>
CAF_DEPRECATED infer_typed_actor_handle< typename detail::get_callable_trait< F >::result_type, typename detail::tl_head< typename detail::get_callable_trait< F >::arg_types >::type >::type spawn_typed (F fun, Ts &&...xs)
 
template<class... Ts>
void send (message_priority mp, const channel &dest, Ts &&...xs)
 Sends {xs...} to dest using the priority mp.
 
template<class... Ts>
void send (const channel &dest, Ts &&...xs)
 Sends {xs...} to dest using normal priority.
 
template<class... Sigs, class... Ts>
void send (message_priority mp, const typed_actor< Sigs...> &dest, Ts &&...xs)
 Sends {xs...} to dest using the priority mp.
 
template<class... Sigs, class... Ts>
void send (const typed_actor< Sigs...> &dest, Ts &&...xs)
 Sends {xs...} to dest using normal priority.
 
void send_exit (const actor_addr &dest, uint32_t reason)
 Sends an exit message to dest.
 
template<class ActorHandle >
void send_exit (const ActorHandle &dest, uint32_t reason)
 Sends an exit message to dest.
 
template<class... Ts>
void delayed_send (message_priority mp, const channel &dest, const duration &rtime, Ts &&...xs)
 Sends a message to dest that is delayed by rel_time using the priority mp. More...
 
template<class... Ts>
void delayed_send (const channel &dest, const duration &rtime, Ts &&...xs)
 Sends a message to dest that is delayed by rel_time.
 
template<class... Sigs, class... Ts>
void delayed_send (message_priority mp, const typed_actor< Sigs...> &dest, const duration &rtime, Ts &&...xs)
 Sends {xs...} delayed by rtime to dest using the priority mp.
 
template<class... Sigs, class... Ts>
void delayed_send (const typed_actor< Sigs...> &dest, const duration &rtime, Ts &&...xs)
 Sends {xs...} delayed by rtime to dest using the priority mp.
 
void join (const group &what)
 Causes this actor to subscribe to the group what. More...
 
void leave (const group &what)
 Causes this actor to leave the group what.
 
void quit (uint32_t reason=exit_reason::normal)
 Finishes execution of this actor after any currently running message handler is done. More...
 
bool trap_exit () const
 Checks whether this actor traps exit messages.
 
void trap_exit (bool value)
 Enables or disables trapping of exit messages.
 
messagecurrent_message ()
 Returns the currently processed message. More...
 
actor_addrcurrent_sender ()
 Returns the address of the sender of the current message. More...
 
void monitor (const actor_addr &whom)
 Adds a unidirectional monitor to whom. More...
 
void monitor (const actor &whom)
 Adds a unidirectional monitor to whom. More...
 
template<class... Ts>
void monitor (const typed_actor< Ts...> &whom)
 Adds a unidirectional monitor to whom. More...
 
void demonitor (const actor_addr &whom)
 Removes a monitor from whom.
 
void demonitor (const actor &whom)
 Removes a monitor from whom.
 
virtual void on_exit ()
 Can be overridden to perform cleanup code after an actor finished execution. More...
 
std::vector< group > joined_groups () const
 Returns all joined groups.
 
response_promise make_response_promise ()
 Creates a response_promise to response to a request later on.
 
void on_sync_failure (std::function< void()> fun)
 Sets the handler for unexpected synchronous response messages.
 
bool has_sync_failure_handler () const
 Checks wheter this actor has a user-defined sync failure handler.
 
template<class F >
void set_exception_handler (F f)
 Sets a custom exception handler for this actor. More...
 
virtual void save_state (serializer &sink, const unsigned int version)
 Serializes the state of this actor to sink. More...
 
virtual void load_state (deserializer &source, const unsigned int version)
 Deserializes the state of this actor from source. More...
 
messagelast_dequeued () CAF_DEPRECATED
 
actor_addrlast_sender () CAF_DEPRECATED
 
void attach_to_scheduler () override
 Initializes this object, e.g., by increasing the the reference count.
 
void detach_from_scheduler () override
 Uninitializes this object, e.g., by decrementing the the reference count.
 
resumable::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...
 
- Public Member Functions inherited from caf::abstract_actor
void attach (attachable_ptr ptr)
 Attaches ptr to this actor. More...
 
template<class F >
void attach_functor (F f)
 Convenience function that attaches the functor f to this actor. More...
 
actor_addr address () const
 Returns the logical actor address.
 
size_t detach (const attachable::token &what)
 Detaches the first attached object that matches what.
 
void link_to (const actor_addr &whom)
 Links this actor to whom.
 
template<class ActorHandle >
void link_to (const ActorHandle &whom)
 Links this actor to whom.
 
void unlink_from (const actor_addr &other)
 Unlinks this actor from whom.
 
template<class ActorHandle >
void unlink_from (const ActorHandle &other)
 Unlinks this actor from whom.
 
bool establish_backlink (const actor_addr &other)
 Establishes a link relation between this actor and other and returns whether the operation succeeded. More...
 
bool remove_backlink (const actor_addr &other)
 Removes the link relation between this actor and other and returns whether the operation succeeded. More...
 
uint32_t id () const
 Returns the unique ID of this actor.
 
uint32_t exit_reason () const
 Returns the actor's exit reason or exit_reason::not_exited if it's still alive. More...
 
virtual std::set< std::string > message_types () const
 Returns the set of accepted messages types as strings or an empty set if this actor is untyped. More...
 
execution_unithost () const
 Returns the execution unit currently used by this actor. More...
 
void host (execution_unit *new_host)
 Sets the execution unit for this actor.
 
- Public Member Functions inherited from caf::abstract_channel
node_id node () const
 Returns the ID of the node this actor is running on.
 
bool is_remote () const
 Returns true if node_ptr returns.
 
bool is_abstract_actor () const
 
bool is_abstract_group () const
 
- Public Member Functions inherited from caf::ref_counted
 ref_counted (const ref_counted &)
 
ref_countedoperator= (const ref_counted &)
 
void ref () noexcept
 Increases reference count by one.
 
void deref () noexcept
 Decreases reference count by one and calls request_deletion when it drops to zero. More...
 
bool unique () const noexcept
 Queries whether there is exactly one reference.
 
size_t get_reference_count () const noexcept
 
- Public Member Functions inherited from caf::memory_managed
virtual void request_deletion (bool decremented_rc) noexcept
 Default implementations calls `delete this, but can be overriden in case deletion depends on some condition or the class doesn't use default new/delete. 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 (middleman &parent_ref)
 
network::multiplexerbackend ()
 Returns the multiplexer running this broker.
 
template<class Handle >
auto by_id (Handle hdl) -> 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...
 
- Protected Member Functions inherited from caf::abstract_actor
 abstract_actor ()
 Creates a non-proxy instance.
 
 abstract_actor (actor_id aid, node_id nid)
 Creates a proxy instance for a proxy running on nid.
 
bool exited () const
 Returns exit_reason() != exit_reason::not_exited.
 
- Protected Member Functions inherited from caf::abstract_channel
int flags () const
 
void flags (int new_value)
 

Friends

class scribe
 
class doorman
 
class continuation
 

Additional Inherited Members

- Public Types inherited from caf::local_actor
using mailbox_type = detail::single_reader_queue< mailbox_element, detail::disposer >
 
- Public Types inherited from caf::resumable
enum  resume_result {
  resume_later,
  awaiting_message,
  done,
  shutdown_execution_unit
}
 
- Static Public Attributes inherited from caf::local_actor
static constexpr auto memory_cache_flag = detail::needs_embedding
 
- Static Public Attributes inherited from caf::abstract_channel
static constexpr int is_abstract_actor_flag = 0x100000
 
static constexpr int is_abstract_group_flag = 0x200000
 
- Protected Attributes inherited from caf::ref_counted
std::atomic< size_t > rc_
 

Detailed Description

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

Member Function Documentation

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.
Exceptions
network_errorThrown if port was unavailable.
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.
Exceptions
network_errorThrown if given host was unreachable or invalid.
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.

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 >
void 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  config 
)

Modifies the receive policy for given connection.

Parameters
hdlIdentifies the affected connection.
configContains the new receive policy.
void caf::io::abstract_broker::enqueue ( mailbox_element_ptr  what,
execution_unit host 
)
overridevirtual

Enqueues a new message wrapped in a mailbox_element to the channel.

This variant is used by actors whenever it is possible to allocate mailbox element and message on the same memory block and is thus more efficient. Non-actors use the default implementation which simply calls the pure virtual version.

Reimplemented from caf::abstract_channel.

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.

const char* caf::io::abstract_broker::name ( ) const
overridevirtual

Returns an implementation-dependent name for logging purposes, which is only valid as long as the actor is running.

The default implementation simply returns "actor".

Reimplemented from caf::local_actor.

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.

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: