libcaf
0.13.2
|
An co-existing forwarding all messages through a user-defined callback to another object, thus serving as gateway to allow any object to interact with other actors. More...
#include <actor_companion.hpp>
Public Types | |
using | lock_type = detail::shared_spinlock |
using | message_pointer = std::unique_ptr< mailbox_element, detail::disposer > |
using | enqueue_handler = std::function< void(message_pointer)> |
![]() | |
using | mailbox_type = detail::single_reader_queue< mailbox_element, detail::disposer > |
![]() | |
enum | resume_result { resume_later, awaiting_message, done, shutdown_execution_unit } |
Public Member Functions | |
void | disconnect (std::uint32_t rsn=exit_reason::normal) |
Removes the handler for incoming messages and terminates the companion for exit reason @ rsn. More... | |
void | on_enqueue (enqueue_handler handler) |
Sets the handler for incoming messages. More... | |
void | enqueue (mailbox_element_ptr what, execution_unit *host) override |
Enqueues a new message wrapped in a mailbox_element to the channel. More... | |
void | enqueue (const actor_addr &sender, message_id mid, message content, execution_unit *host) override |
Enqueues a new message to the channel. | |
void | initialize () |
![]() | |
template<class T , spawn_options Os = no_spawn_options, class... Ts> | |
actor | spawn (Ts &&...xs) |
template<spawn_options Os = no_spawn_options, class... Ts> | |
actor | spawn (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> | |
actor_handle_from_signature_list< typename T::signatures >::type | spawn_typed (Ts &&...xs) |
template<spawn_options Os = no_spawn_options, typename F , class... Ts> | |
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. | |
message & | current_message () |
Returns the currently processed message. More... | |
actor_addr & | current_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 () |
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... | |
message & | last_dequeued () CAF_DEPRECATED |
actor_addr & | last_sender () CAF_DEPRECATED |
void | send_tuple (message_priority mp, const channel &whom, message what) CAF_DEPRECATED |
void | send_tuple (const channel &whom, message what) CAF_DEPRECATED |
void | delayed_send_tuple (message_priority mp, const channel &whom, const duration &rtime, message data) CAF_DEPRECATED |
void | delayed_send_tuple (const channel &whom, const duration &rtime, message data) 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... | |
![]() | |
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_unit * | host () const |
Returns the execution unit currently used by this actor. More... | |
void | host (execution_unit *new_host) |
Sets the execution unit for this actor. | |
![]() | |
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 |
![]() | |
ref_counted (const ref_counted &) | |
ref_counted & | operator= (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 |
![]() | |
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... | |
Related Functions | |
(Note that these are not member functions.) | |
using | actor_companion_ptr = intrusive_ptr< actor_companion > |
A pointer to a co-existing (actor) object. | |
![]() | |
using | local_actor_ptr = intrusive_ptr< local_actor > |
A smart pointer to a local_actor instance. | |
constexpr keep_behavior_t | keep_behavior = keep_behavior_t{} |
Policy tag that causes event_based_actor::become to keep the current behavior available. | |
![]() | |
using | actor_id = uint32_t |
A unique actor ID. | |
![]() | |
void | intrusive_ptr_add_ref (ref_counted *p) |
void | intrusive_ptr_release (ref_counted *p) |
Additional Inherited Members | |
![]() | |
static constexpr auto | memory_cache_flag = detail::needs_embedding |
![]() | |
static constexpr int | is_abstract_actor_flag = 0x100000 |
static constexpr int | is_abstract_group_flag = 0x200000 |
![]() | |
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 . | |
void | cleanup (uint32_t reason) |
Called by the runtime system to perform cleanup actions for this actor. More... | |
bool | exited () const |
Returns exit_reason() != exit_reason::not_exited . | |
![]() | |
int | flags () const |
void | flags (int new_value) |
![]() | |
std::atomic< size_t > | rc_ |
An co-existing forwarding all messages through a user-defined callback to another object, thus serving as gateway to allow any object to interact with other actors.
void caf::actor_companion::disconnect | ( | std::uint32_t | rsn = exit_reason::normal | ) |
Removes the handler for incoming messages and terminates the companion for exit reason @ rsn.
|
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.
void caf::actor_companion::on_enqueue | ( | enqueue_handler | handler | ) |
Sets the handler for incoming messages.
handler
needs to be thread-safe