C++ Actor Framework 0.19
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Protected Attributes | Related Symbols | List of all members
caf::local_actor Class Referenceabstract

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::monitorable_actor caf::abstract_actor caf::abstract_channel caf::actor_companion caf::blocking_actor caf::io::typed_broker< Sigs > caf::typed_event_based_actor< Sigs >

Classes

struct  inbound_stream_metrics_t
 Optional metrics for inbound stream traffic collected by individual actors when configured to do so. More...
 
struct  metrics_t
 Optional metrics collected by individual actors when configured to do so. More...
 
struct  outbound_stream_metrics_t
 Optional metrics for outbound stream traffic collected by individual actors when configured to do so. More...
 

Public Types

using clock_type = std::chrono::steady_clock
 Defines a monotonic clock suitable for measuring intervals.
 

Public Member Functions

 local_actor (actor_config &cfg)
 
void on_destroy () override
 Cleans up any remaining state before the destructor is called.
 
void setup_metrics ()
 
virtual void launch (execution_unit *eu, bool lazy, bool hide)=0
 
clock_type::time_point now () const noexcept
 Returns the current time.
 
disposable request_response_timeout (timespan d, message_id mid)
 Requests a new timeout for mid.
 
template<class T , spawn_options Os = no_spawn_options, class... Ts>
infer_handle_from_class_t< T > spawn (Ts &&... xs)
 
template<spawn_options Os = no_spawn_options, class F , class... Ts>
infer_handle_from_fun_t< F > spawn (F fun, Ts &&... xs)
 
template<class T , spawn_options Os = no_spawn_options, class Groups , class... Ts>
actor spawn_in_groups (const Groups &gs, Ts &&... xs)
 
template<class T , spawn_options Os = no_spawn_options, class... Ts>
actor spawn_in_groups (std::initializer_list< group > gs, 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 F , class... Ts>
actor spawn_in_groups (const Groups &gs, F fun, Ts &&... xs)
 
template<spawn_options Os = no_spawn_options, class F , class... Ts>
actor spawn_in_groups (std::initializer_list< group > gs, F fun, Ts &&... xs)
 
template<spawn_options Os = no_spawn_options, class F , class... Ts>
actor spawn_in_group (const group &grp, F fun, Ts &&... xs)
 
void send_exit (const actor_addr &whom, error reason)
 Sends an exit message to whom.
 
void send_exit (const strong_actor_ptr &whom, error reason)
 Sends an exit message to whom.
 
template<class ActorHandle >
void send_exit (const ActorHandle &whom, error reason)
 Sends an exit message to whom.
 
execution_unitcontext () const noexcept
 Returns the execution unit currently used by this actor.
 
void context (execution_unit *x) noexcept
 Sets the execution unit for this actor.
 
actor_systemsystem () const noexcept
 Returns the hosting actor system.
 
const actor_system_configconfig () const noexcept
 Returns the config of the hosting actor system.
 
actor_clockclock () const noexcept
 Returns the clock of the actor system.
 
strong_actor_ptrcurrent_sender () noexcept
 Returns a pointer to the sender of the current message.
 
message_id current_message_id () noexcept
 Returns the ID of the current message.
 
message_id take_current_message_id () noexcept
 Returns the ID of the current message and marks the ID stored in the current mailbox element as answered.
 
void drop_current_message_id () noexcept
 Marks the current message ID as answered.
 
strong_actor_ptr current_next_stage () noexcept
 Returns a pointer to the next stage from the forwarding path of the current message or nullptr if the path is empty.
 
strong_actor_ptr take_current_next_stage ()
 Returns a pointer to the next stage from the forwarding path of the current message and removes it from the path.
 
const mailbox_element::forwarding_stack & current_forwarding_stack () noexcept
 Returns the forwarding stack from the current mailbox element.
 
mailbox_element::forwarding_stack take_current_forwarding_stack () noexcept
 Moves the forwarding stack from the current mailbox element.
 
mailbox_element * current_mailbox_element () noexcept
 Returns a pointer to the currently processed mailbox element.
 
void monitor (const node_id &node)
 Adds a unidirectional monitor to node.
 
template<message_priority P = message_priority::normal, class Handle >
void monitor (const Handle &whom)
 Adds a unidirectional monitor to whom.
 
void demonitor (const actor_addr &whom)
 Removes a monitor from whom.
 
void demonitor (const strong_actor_ptr &whom)
 Removes a monitor from whom.
 
void demonitor (const node_id &node)
 Removes a monitor from node.
 
template<class Handle >
void demonitor (const Handle &whom)
 Removes a monitor from whom.
 
virtual void on_exit ()
 Can be overridden to perform cleanup code after an actor finished execution.
 
template<class... Ts>
detail::response_promise_t< Ts... > make_response_promise ()
 Creates a typed_response_promise to respond to a request later on.
 
response_promise make_response_promise ()
 Creates a response_promise to respond to a request later on.
 
const char * name () const override
 Returns an implementation-dependent name for logging purposes, which is only valid as long as the actor is running.
 
virtual error save_state (serializer &sink, unsigned int version)
 Serializes the state of this actor to sink.
 
virtual error load_state (deserializer &source, unsigned int version)
 Deserializes the state of this actor from source.
 
const errorfail_state () const noexcept
 Returns the currently defined fail state.
 
- Public Member Functions inherited from caf::monitorable_actor
virtual const char * name () const
 Returns an implementation-dependent name for logging purposes, which is only valid as long as the actor is running.
 
void attach (attachable_ptr ptr) override
 Attaches ptr to this actor.
 
size_t detach (const attachable::token &what) override
 Detaches the first attached object that matches what.
 
void link_to (const actor_addr &x)
 Links this actor to x.
 
template<class ActorHandle >
void link_to (const ActorHandle &x)
 Links this actor to x.
 
void unlink_from (const actor_addr &x)
 Unlinks this actor from x.
 
template<class ActorHandle >
void unlink_from (const ActorHandle &x)
 Links this actor to x.
 
- Public Member Functions inherited from caf::abstract_actor
actor_control_blockctrl () const
 
 abstract_actor (const abstract_actor &)=delete
 
abstract_actoroperator= (const abstract_actor &)=delete
 
virtual void on_destroy ()
 Cleans up any remaining state before the destructor is called.
 
bool enqueue (strong_actor_ptr sender, message_id mid, message msg, execution_unit *host) override
 Enqueues a new message without forwarding stack to the channel.
 
virtual bool enqueue (mailbox_element_ptr what, execution_unit *host)=0
 Enqueues a new message wrapped in a mailbox_element to the actor.
 
virtual void attach (attachable_ptr ptr)=0
 Attaches ptr to this actor.
 
template<class F >
void attach_functor (F f)
 Convenience function that attaches the functor f to this actor.
 
actor_addr address () const noexcept
 Returns the logical actor address.
 
virtual size_t detach (const attachable::token &what)=0
 Detaches the first attached object that matches what.
 
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.
 
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).
 
- Public Member Functions inherited from caf::abstract_channel
virtual bool enqueue (strong_actor_ptr sender, message_id mid, message content, execution_unit *host=nullptr)=0
 Enqueues a new message without forwarding stack to the channel.
 
bool is_abstract_actor () const
 
bool is_abstract_group () const
 
bool is_actor_decorator () const
 

Protected Attributes

execution_unitcontext_
 
mailbox_element * current_element_
 
message_id last_request_id_
 
detail::unique_function< behavior(local_actor *)> initial_behavior_fac_
 Factory function for returning initial behavior in function-based actors.
 
metrics_t metrics_
 
- Protected Attributes inherited from caf::monitorable_actor
error fail_state_
 
std::condition_variable cv_
 
attachable_ptr attachables_head_
 
- Protected Attributes inherited from caf::abstract_actor
std::mutex mtx_
 

Related Symbols

(Note that these are not member symbols.)

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

- Static Public Attributes inherited from caf::abstract_channel
static constexpr int is_abstract_actor_flag = 0x01000000
 
static constexpr int is_abstract_group_flag = 0x02000000
 
static constexpr int is_actor_bind_decorator_flag = 0x04000000
 
static constexpr int is_actor_dot_decorator_flag = 0x08000000
 
static constexpr int is_actor_decorator_mask = 0x0C000000
 
static constexpr int is_hidden_flag = 0x10000000
 
- Protected Member Functions inherited from caf::monitorable_actor
virtual void on_cleanup (const error &reason)
 Allows subclasses to add additional cleanup code to the critical section in cleanup.
 
void bounce (mailbox_element_ptr &what)
 Sends a response message if what is a request.
 
void bounce (mailbox_element_ptr &what, const error &err)
 Sends a response message if what is a request.
 
 monitorable_actor (actor_config &cfg)
 Creates a new actor instance.
 
void attach_impl (attachable_ptr &ptr)
 
size_t detach_impl (const attachable::token &what, bool stop_on_hit=false, bool dry_run=false)
 
bool handle_system_message (mailbox_element &x, execution_unit *ctx, bool trap_exit)
 
template<class F >
bool handle_system_message (mailbox_element &x, execution_unit *context, bool trap_exit, F &down_msg_handler)
 
- Protected Member Functions inherited from caf::abstract_actor
 abstract_actor (actor_config &cfg)
 
- Protected Member Functions inherited from caf::abstract_channel
int flags () const
 
void flags (int new_value)
 

Detailed Description

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

Member Function Documentation

◆ current_sender()

strong_actor_ptr & caf::local_actor::current_sender ( )
noexcept

Returns a pointer to the sender of the current message.

Precondition
current_mailbox_element() != nullptr

◆ fail_state()

const error & caf::local_actor::fail_state ( ) const
noexcept

Returns the currently defined fail state.

If this reason is not none then the actor will terminate with this error after executing the current message handler.

◆ load_state()

error caf::local_actor::load_state ( deserializer source,
unsigned int  version 
)
virtual

Deserializes the state of this actor from source.

This function is only called if this actor has set the is_serializable flag. The default implementation throws a std::logic_error.

◆ make_response_promise()

template<class... Ts>
detail::response_promise_t< Ts... > caf::local_actor::make_response_promise ( )

Creates a typed_response_promise to respond to a request later on.

make_response_promise<typed_response_promise<int, int>>() is equivalent to make_response_promise<int, int>().

◆ monitor() [1/2]

template<message_priority P = message_priority::normal, class Handle >
void caf::local_actor::monitor ( const Handle &  whom)

Adds a unidirectional monitor to whom.

Note
Each call to monitor creates a new, independent monitor.

◆ monitor() [2/2]

void caf::local_actor::monitor ( const node_id node)

Adds a unidirectional monitor to node.

Note
Each call to monitor creates a new, independent monitor.

◆ name()

const char * caf::local_actor::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::monitorable_actor.

◆ on_destroy()

void caf::local_actor::on_destroy ( )
overridevirtual

Cleans up any remaining state before the destructor is called.

This function makes sure it is safe to call virtual functions in sub classes before destroying the object, because calling virtual function in the destructor itself is not safe. Any override implementation is required to call super::destroy() at the end.

Reimplemented from caf::abstract_actor.

◆ on_exit()

void caf::local_actor::on_exit ( )
virtual

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

Reimplemented in caf::actor_companion.

◆ request_response_timeout()

disposable caf::local_actor::request_response_timeout ( timespan  d,
message_id  mid 
)

Requests a new timeout for mid.

Precondition
mid.is_request()

◆ save_state()

error caf::local_actor::save_state ( serializer sink,
unsigned int  version 
)
virtual

Serializes the state of this actor to sink.

This function is only called if this actor has set the is_serializable flag. The default implementation throws a std::logic_error.

◆ take_current_next_stage()

strong_actor_ptr caf::local_actor::take_current_next_stage ( )

Returns a pointer to the next stage from the forwarding path of the current message and removes it from the path.

Returns nullptr if the path is empty.


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