actor-framework
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | Related Functions | List of all members
caf::abstract_actor Class Referenceabstract

Base class for all actor implementations. More...

#include <abstract_actor.hpp>

Inheritance diagram for caf::abstract_actor:
Inheritance graph
[legend]
Collaboration diagram for caf::abstract_actor:
Collaboration graph
[legend]

Public Member Functions

 abstract_actor (const abstract_actor &)=delete
 
abstract_actoroperator= (const abstract_actor &)=delete
 
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...
 
size_t detach (const attachable::token &what)
 Detaches the first attached object that matches what.
 
void link_to (const actor_addr &other)
 Links this actor to other.
 
template<class ActorHandle >
void link_to (const ActorHandle &other)
 Links this actor to other.
 
void unlink_from (const actor_addr &other)
 Unlinks this actor from addr.
 
template<class ActorHandle >
void unlink_from (const ActorHandle &other)
 Links this actor to hdl.
 
virtual const char * name () const =0
 Returns an implementation-dependent name for logging purposes, which is only valid as long as the actor is running. 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...
 
actor_id id () const noexcept
 Returns the ID of this actor.
 
node_id node () const noexcept
 Returns the node this actor is living on.
 
actor_systemhome_system () const noexcept
 Returns the system that created this actor (or proxy).
 
actor_control_blockctrl () const
 Returns the control block for this actor.
 
actor_addr address () const noexcept
 Returns the logical actor address.
 
virtual bool enqueue (mailbox_element_ptr what, scheduler *sched)=0
 Enqueues a new message wrapped in a mailbox_element to the actor. More...
 
virtual mailbox_elementpeek_at_next_mailbox_element ()
 Called by the testing DSL to peek at the next element in the mailbox. More...
 
bool cleanup (error &&reason, scheduler *sched)
 Called by the runtime system to perform cleanup actions for this actor. More...
 

Protected Member Functions

virtual void on_unreachable ()
 Called on actor if the last strong reference to it expired without a prior call to quit(exit_reason::not_exited). More...
 
virtual void on_cleanup (const error &reason)
 Called from cleanup to perform extra cleanup actions for this actor.
 
int flags () const
 
void flags (int new_value)
 
bool is_terminated () const noexcept
 Checks whether this actor has terminated.
 
 abstract_actor (actor_config &cfg)
 
void attach_impl (attachable_ptr &ptr)
 
size_t detach_impl (const attachable::token &what, bool stop_on_hit=false, bool dry_run=false)
 
void add_link (abstract_actor *other)
 Causes the actor to establish a link to other.
 
void remove_link (abstract_actor *other)
 Causes the actor to remove any established link to other.
 
virtual bool add_backlink (abstract_actor *other)
 Adds an entry to other to the link table of this actor. More...
 
virtual bool remove_backlink (abstract_actor *other)
 Removes an entry to other from the link table of this actor. More...
 

Protected Attributes

std::atomic< int > flags_
 Holds several state and type flags.
 
std::mutex mtx_
 Guards members that may be subject to concurrent access . More...
 
std::condition_variable cv_
 Allows blocking actors to actively wait for incoming messages.
 
error fail_state_
 Stores the user-defined exit reason if this actor has finished execution.
 
attachable_ptr attachables_head_
 Points to the first attachable in the linked list of attachables (if any).
 

Friends

template<class T >
class actor_storage
 
template<class >
class caf::io::basp::remote_message_handler
 
CAF_CORE_EXPORT void intrusive_ptr_release (actor_control_block *)
 

Related Functions

(Note that these are not member functions.)

using actor_id = uint64_t
 A unique actor ID.
 

Detailed Description

Base class for all actor implementations.

Member Function Documentation

◆ add_backlink()

bool caf::abstract_actor::add_backlink ( abstract_actor other)
protectedvirtual

Adds an entry to other to the link table of this actor.

Warning
Must be called inside a critical section, i.e., while holding mtx_.

Reimplemented in caf::forwarding_actor_proxy.

◆ attach()

void caf::abstract_actor::attach ( attachable_ptr  ptr)

Attaches ptr to this actor.

The actor will call ptr->detach(...) on exit, or immediately if it already finished execution.

◆ attach_functor()

template<class F >
void caf::abstract_actor::attach_functor ( f)
inline

Convenience function that attaches the functor f to this actor.

The actor executes f() on exit or immediately if it is not running.

◆ cleanup()

bool caf::abstract_actor::cleanup ( error &&  reason,
scheduler sched 
)

Called by the runtime system to perform cleanup actions for this actor.

Subtypes should always call this member function when overriding it. This member function is thread-safe, and if the actor has already exited upon invocation, nothing is done. The return value of this member function is ignored by scheduled actors.

◆ enqueue()

virtual bool caf::abstract_actor::enqueue ( mailbox_element_ptr  what,
scheduler sched 
)
pure virtual

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

This enqueue variant allows to define forwarding chains.

Returns
true if the message has added to the mailbox, false otherwise. In the latter case, the actor terminated and the message has been dropped. Once this function returns false, it returns false for all future invocations.
Note
The returned value is purely informational and may be used to discard actor handles early. Messages may still get dropped later even if this function returns true. In particular when dealing with remote actors.

Implemented in test_coordinator_fixture< Config >::test_coordinator_impl::dummy_printer, caf::scheduled_actor, caf::blocking_actor, caf::net::abstract_actor_shell, caf::actor_pool, caf::io::abstract_broker, caf::actor_companion, and caf::forwarding_actor_proxy.

◆ message_types()

std::set< std::string > caf::abstract_actor::message_types ( ) const
virtual

Returns the set of accepted messages types as strings or an empty set if this actor is untyped.

◆ name()

virtual const char* caf::abstract_actor::name ( ) const
pure virtual

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

Implemented in test_coordinator_fixture< Config >::test_coordinator_impl::dummy_printer, caf::local_actor, caf::io::abstract_broker, caf::scheduled_actor, caf::blocking_actor, caf::actor_pool, caf::io::basp_broker, caf::detail::prometheus_broker, and caf::forwarding_actor_proxy.

◆ on_unreachable()

void caf::abstract_actor::on_unreachable ( )
protectedvirtual

Called on actor if the last strong reference to it expired without a prior call to quit(exit_reason::not_exited).

Precondition
getf(is_terminated_flag) == false
Postcondition
getf(is_terminated_flag) == true

◆ peek_at_next_mailbox_element()

mailbox_element * caf::abstract_actor::peek_at_next_mailbox_element ( )
virtual

Called by the testing DSL to peek at the next element in the mailbox.

Do not call this function in production code! The default implementation always returns nullptr.

Returns
A pointer to the next mailbox element or nullptr if the mailbox is empty or the actor does not have a mailbox.

Reimplemented in caf::scheduled_actor, caf::blocking_actor, and caf::net::abstract_actor_shell.

◆ remove_backlink()

bool caf::abstract_actor::remove_backlink ( abstract_actor other)
protectedvirtual

Removes an entry to other from the link table of this actor.

Warning
Must be called inside a critical section, i.e., while holding mtx_.

Reimplemented in caf::forwarding_actor_proxy.

Member Data Documentation

◆ mtx_

std::mutex caf::abstract_actor::mtx_
mutableprotected

Guards members that may be subject to concurrent access .

For example, exit_state_, attachables_, and links_.


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