C++ Actor Framework
0.18
|
A thread-mapped or context-switching actor using a blocking receive rather than a behavior-stack based message processing. More...
#include <blocking_actor.hpp>
Classes | |
class | accept_one_cond |
Pseudo receive condition modeling a single receive. More... | |
struct | do_receive_helper |
Implementation helper for blocking_actor::do_receive . More... | |
struct | mailbox_policy |
Configures the FIFO inbox with two nested queues: More... | |
class | receive_cond |
Represents pre- and postconditions for receive loops. More... | |
struct | receive_for_helper |
Implementation helper for blocking_actor::receive_for . More... | |
struct | receive_while_helper |
Implementation helper for blocking_actor::receive_while . More... | |
Public Types | |
using | super = extended_base |
Base type. | |
using | normal_queue = intrusive::drr_cached_queue< policy::normal_messages > |
Stores asynchronous messages with default priority. | |
using | urgent_queue = intrusive::drr_cached_queue< policy::urgent_messages > |
Stores asynchronous messages with high priority. | |
using | mailbox_type = intrusive::fifo_inbox< mailbox_policy > |
A queue optimized for single-reader-many-writers. | |
using | timeout_type = std::chrono::high_resolution_clock::time_point |
Absolute timeout type. | |
using | behavior_type = behavior |
Supported behavior type. | |
using | signatures = none_t |
Declared message passing interface. | |
![]() | |
using | clock_type = std::chrono::steady_clock |
Defines a monotonic clock suitable for measuring intervals. | |
Public Member Functions | |
blocking_actor (actor_config &cfg) | |
void | enqueue (mailbox_element_ptr, execution_unit *) override |
Enqueues a new message wrapped in a mailbox_element to the actor. More... | |
mailbox_element * | peek_at_next_mailbox_element () override |
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... | |
void | launch (execution_unit *eu, bool lazy, bool hide) override |
virtual void | act () |
Implements the actor's behavior. | |
template<class... Ts> | |
void | receive (Ts &&... xs) |
Dequeues the next message from the mailbox that is matched by given behavior. More... | |
template<class T > | |
receive_for_helper< T > | receive_for (T &begin, T end) |
Receives messages for range [begin, first) . More... | |
receive_while_helper | receive_while (std::function< bool()> stmt) |
Receives messages as long as stmt returns true. More... | |
receive_while_helper | receive_while (const bool &ref) |
Receives messages as long as ref is true. More... | |
template<class... Ts> | |
do_receive_helper | do_receive (Ts &&... xs) |
Receives messages until stmt returns true. More... | |
void | await_all_other_actors_done () |
Blocks this actor until all other actors are done. | |
template<class... Ts> | |
void | wait_for (Ts &&... xs) |
Blocks this actor until all xs... have terminated. | |
void | fail_state (error err) |
Sets a user-defined exit reason err . More... | |
virtual void | await_data () |
Blocks until at least one message is in the mailbox. | |
virtual bool | await_data (timeout_type timeout) |
Blocks until at least one message is in the mailbox or the absolute timeout was reached. More... | |
virtual mailbox_element_ptr | dequeue () |
Returns the next element from the mailbox or nullptr . | |
mailbox_type & | mailbox () |
Returns the queue for storing incoming messages. | |
![]() | |
local_actor (actor_config &cfg) | |
void | on_destroy () override |
Cleans up any remaining state before the destructor is called. More... | |
void | setup_metrics () |
clock_type::time_point | now () const noexcept |
Returns the current time. | |
void | request_response_timeout (timespan d, message_id mid) |
Requests a new timeout for mid . More... | |
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_unit * | context () 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_system & | system () const noexcept |
Returns the hosting actor system. | |
const actor_system_config & | config () const noexcept |
Returns the config of the hosting actor system. | |
actor_clock & | clock () const noexcept |
Returns the clock of the actor system. | |
strong_actor_ptr & | current_sender () noexcept |
Returns a pointer to the sender of the current message. More... | |
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. More... | |
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. More... | |
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. More... | |
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 . More... | |
template<message_priority P = message_priority::normal, class Handle > | |
void | monitor (const Handle &whom) |
Adds a unidirectional monitor to whom . More... | |
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. More... | |
template<class... Ts> | |
detail::response_promise_t< Ts... > | make_response_promise () |
Creates a typed_response_promise to respond to a request later on. More... | |
response_promise | make_response_promise () |
Creates a response_promise to respond to a request later on. | |
template<class... Ts> | |
detail::response_promise_t< std::decay_t< Ts >... > | response (Ts &&... xs) |
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... | |
virtual error | save_state (serializer &sink, unsigned int version) |
Serializes the state of this actor to sink . More... | |
virtual error | load_state (deserializer &source, unsigned int version) |
Deserializes the state of this actor from source . More... | |
const error & | fail_state () const noexcept |
Returns the currently defined fail state. More... | |
![]() | |
void | attach (attachable_ptr ptr) override |
Attaches ptr to this actor. More... | |
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 . | |
![]() | |
void * | operator new (std::size_t, void *ptr) |
actor_control_block * | ctrl () const |
void | enqueue (strong_actor_ptr sender, message_id mid, message msg, execution_unit *host) override |
Enqueues a new message without forwarding stack to the channel. | |
template<class F > | |
void | attach_functor (F f) |
Convenience function that attaches the functor f to this actor. More... | |
actor_addr | address () const noexcept |
Returns the logical actor address. | |
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_system & | home_system () const noexcept |
Returns the system that created this actor (or proxy). | |
![]() | |
bool | is_abstract_actor () const |
bool | is_abstract_group () const |
bool | is_actor_decorator () const |
Additional Inherited Members | |
![]() | |
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 |
![]() | |
virtual void | on_cleanup (const error &reason) |
Allows subclasses to add additional cleanup code to the critical section in cleanup . More... | |
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) |
![]() | |
abstract_actor (actor_config &cfg) | |
Creates a new actor instance. | |
![]() | |
int | flags () const |
void | flags (int new_value) |
![]() | |
execution_unit * | context_ |
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_ |
![]() | |
error | fail_state_ |
std::condition_variable | cv_ |
attachable_ptr | attachables_head_ |
![]() | |
std::mutex | mtx_ |
![]() | |
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 = uint64_t |
A unique actor ID. | |
A thread-mapped or context-switching actor using a blocking receive rather than a behavior-stack based message processing.
|
virtual |
Blocks until at least one message is in the mailbox or the absolute timeout
was reached.
do_receive_helper caf::blocking_actor::do_receive | ( | Ts &&... | xs | ) |
Receives messages until stmt
returns true.
Semantically equal to: do { receive(...); } while (stmt() == false);
Usage example:
|
overridevirtual |
Enqueues a new message wrapped in a mailbox_element
to the actor.
This enqueue
variant allows to define forwarding chains.
Implements caf::abstract_actor.
void caf::blocking_actor::fail_state | ( | error | err | ) |
Sets a user-defined exit reason err
.
This reason is signalized to other actors after act()
returns.
|
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.
void caf::blocking_actor::receive | ( | Ts &&... | xs | ) |
Dequeues the next message from the mailbox that is matched by given behavior.
receive_for_helper<T> caf::blocking_actor::receive_for | ( | T & | begin, |
T | end | ||
) |
Receives messages for range [begin, first)
.
Semantically equal to: for ( ; begin != end; ++begin) { receive(...); }
.
Usage example:
receive_while_helper caf::blocking_actor::receive_while | ( | std::function< bool()> | stmt | ) |
Receives messages as long as stmt
returns true.
Semantically equal to: while (stmt()) { receive(...); }
.
Usage example:
receive_while_helper caf::blocking_actor::receive_while | ( | const bool & | ref | ) |
Receives messages as long as ref
is true.
Semantically equal to: while (ref) { receive(...); }
.
Usage example: