libcaf  0.13.2
Public Types | Public Member Functions | Static Public Attributes | Related Functions | List of all members
caf::local_actor Class Reference

Base class for actors running on this node, either living in an own thread or cooperatively scheduled. More...

#include <local_actor.hpp>

Inheritance diagram for caf::local_actor:
caf::abstract_actor caf::resumable caf::abstract_channel caf::ref_counted caf::memory_managed caf::actor_companion caf::blocking_actor caf::event_based_actor caf::io::broker caf::typed_event_based_actor< Sigs > caf::io::basp_broker

Public Types

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
}
 

Public Member Functions

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.
 
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 ()
 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...
 
messagelast_dequeued () CAF_DEPRECATED
 
actor_addrlast_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...
 
- 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
virtual void enqueue (const actor_addr &sender, message_id mid, message content, execution_unit *host)=0
 Enqueues a new message to the channel.
 
virtual void enqueue (mailbox_element_ptr what, execution_unit *host)
 Enqueues a new message wrapped in a mailbox_element to the channel. More...
 
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...
 

Static Public Attributes

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
 

Related Functions

(Note that these are not member functions.)

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.
 

Additional Inherited Members

- 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.
 
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.
 
- Protected Member Functions inherited from caf::abstract_channel
int flags () const
 
void flags (int new_value)
 
- Protected Attributes inherited from caf::ref_counted
std::atomic< size_t > rc_
 

Detailed Description

Base class for actors running on this node, either living in an own thread or cooperatively scheduled.

Member Function Documentation

message& caf::local_actor::current_message ( )

Returns the currently processed message.

Warning
Only set during callback invocation. Calling this member function is undefined behavior (dereferencing a nullptr) when not in a callback or forward_to has been called previously.
actor_addr& caf::local_actor::current_sender ( )

Returns the address of the sender of the current message.

Warning
Only set during callback invocation. Calling this member function is undefined behavior (dereferencing a nullptr) when not in a callback or forward_to has been called previously.
template<class... Ts>
void caf::local_actor::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.

void caf::local_actor::join ( const group &  what)

Causes this actor to subscribe to the group what.

The group will be unsubscribed if the actor finishes execution.

void caf::local_actor::monitor ( const actor_addr whom)

Adds a unidirectional monitor to whom.

Note
Each call to monitor creates a new, independent monitor.
void caf::local_actor::monitor ( const actor whom)

Adds a unidirectional monitor to whom.

Note
Each call to monitor creates a new, independent monitor.
template<class... Ts>
void caf::local_actor::monitor ( const typed_actor< Ts...> &  whom)

Adds a unidirectional monitor to whom.

Note
Each call to monitor creates a new, independent monitor.
virtual void caf::local_actor::on_exit ( )
virtual

Can be overridden to perform cleanup code after an actor finished execution.

Reimplemented in caf::io::basp_broker.

void caf::local_actor::quit ( uint32_t  reason = exit_reason::normal)

Finishes execution of this actor after any currently running message handler is done.

This member function clears the behavior stack of the running actor and invokes on_exit(). The actors does not finish execution if the implementation of on_exit() sets a new behavior. When setting a new behavior in on_exit(), one has to make sure to not produce an infinite recursion.

If on_exit() did not set a new behavior, the actor sends an exit message to all of its linked actors, sets its state to exited and finishes execution.

In case this actor uses the blocking API, this member function unwinds the stack by throwing an actor_exited exception.

Warning
This member function throws immediately in thread-based actors that do not use the behavior stack, i.e., actors that use blocking API calls such as receive().
resumable::resume_result caf::local_actor::resume ( execution_unit ,
size_t  max_throughput 
)
overridevirtual

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

Implements caf::resumable.

template<class F >
void caf::local_actor::set_exception_handler ( f)

Sets a custom exception handler for this actor.

If multiple handlers are defined, only the functor that was added last is being executed.


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