|
| agent_t (environment_t &env) |
| Constructor. More...
|
|
| agent_t (environment_t &env, agent_tuning_options_t tuning_options) |
| Constructor which allows specification of agent's tuning options. More...
|
|
| agent_t (context_t ctx) |
| Constructor which simplifies agent construction with or without agent's tuning options. More...
|
|
virtual | ~agent_t () |
|
const agent_t * | self_ptr () const |
| Get the raw pointer of itself. More...
|
|
agent_t * | self_ptr () |
|
virtual void | so_evt_start () |
| Hook on agent start inside SObjectizer. More...
|
|
virtual void | so_evt_finish () |
| Hook of agent finish in SObjectizer. More...
|
|
const state_t & | so_current_state () const |
| Access to the current agent state. More...
|
|
bool | so_is_active_state (const state_t &state_to_check) const noexcept |
| Is a state activated? More...
|
|
void | so_add_nondestroyable_listener (agent_state_listener_t &state_listener) |
| Add a state listener to the agent. More...
|
|
void | so_add_destroyable_listener (agent_state_listener_unique_ptr_t state_listener) |
| Add a state listener to the agent. More...
|
|
virtual exception_reaction_t | so_exception_reaction () const |
| A reaction from SObjectizer to an exception from agent's event. More...
|
|
void | so_switch_to_awaiting_deregistration_state () |
| Switching agent to special state in case of unhandled exception. More...
|
|
const mbox_t & | so_direct_mbox () const |
| Get the agent's direct mbox. More...
|
|
mbox_t | so_make_new_direct_mbox () |
| Create a new direct mbox for that agent. More...
|
|
environment_t & | so_environment () const |
| Access to the SObjectizer Environment which this agent is belong. More...
|
|
coop_handle_t | so_coop () const |
| Get a handle of agent's coop. More...
|
|
void | so_bind_to_dispatcher (event_queue_t &queue) noexcept |
| Binding agent to the dispatcher. More...
|
|
void | so_deregister_agent_coop (int dereg_reason) |
| A helper method for deregistering agent's coop. More...
|
|
void | so_deregister_agent_coop_normally () |
| A helper method for deregistering agent's coop in case of normal deregistration. More...
|
|
|
void | so_change_state (const state_t &new_state) |
| Change the current state of the agent. More...
|
|
void | so_deactivate_agent () |
| Deactivate the agent. More...
|
|
|
subscription_bind_t | so_subscribe (const mbox_t &mbox_ref) |
| Initiate subscription. More...
|
|
subscription_bind_t | so_subscribe_self () |
| Initiate subscription to agent's direct mbox. More...
|
|
void | so_create_event_subscription (const mbox_t &mbox_ref, std::type_index type_index, const state_t &target_state, const event_handler_method_t &method, thread_safety_t thread_safety, event_handler_kind_t handler_kind) |
| Create a subscription for an event. More...
|
|
void | so_destroy_event_subscription (const mbox_t &mbox, const std::type_index &subscription_type, const state_t &target_state) |
| Destroy event subscription. More...
|
|
template<typename Method_Pointer > |
std::enable_if< details::is_agent_method_pointer< details::method_arity::unary, Method_Pointer >::value, void >::type | so_drop_subscription (const mbox_t &mbox, const state_t &target_state, Method_Pointer) |
| Drop subscription for the state specified. More...
|
|
template<class Message > |
void | so_drop_subscription (const mbox_t &mbox, const state_t &target_state) |
| Drop subscription for the state specified. More...
|
|
template<typename Method_Pointer > |
std::enable_if< details::is_agent_method_pointer< details::method_arity::unary, Method_Pointer >::value, void >::type | so_drop_subscription (const mbox_t &mbox, Method_Pointer) |
| Drop subscription for the default agent state. More...
|
|
template<class Message > |
void | so_drop_subscription (const mbox_t &mbox) |
| Drop subscription for the default agent state. More...
|
|
template<typename Method_Pointer > |
std::enable_if< details::is_agent_method_pointer< details::method_arity::unary, Method_Pointer >::value, void >::type | so_drop_subscription_for_all_states (const mbox_t &mbox, Method_Pointer) |
| Drop subscription for all states. More...
|
|
template<class Message > |
void | so_drop_subscription_for_all_states (const mbox_t &mbox) |
| Drop subscription for all states. More...
|
|
template<class Message > |
bool | so_has_subscription (const mbox_t &mbox, const state_t &target_state) const noexcept |
| Check the presence of a subscription. More...
|
|
template<class Message > |
bool | so_has_subscription (const mbox_t &mbox) const noexcept |
| Check the presence of a subscription in the default_state. More...
|
|
template<typename Method_Pointer > |
std::enable_if< details::is_agent_method_pointer< details::method_arity::unary, Method_Pointer >::value, bool >::type | so_has_subscription (const mbox_t &mbox, const state_t &target_state, Method_Pointer) const noexcept |
| Check the presence of a subscription. More...
|
|
template<typename Method_Pointer > |
std::enable_if< details::is_agent_method_pointer< details::method_arity::unary, Method_Pointer >::value, bool >::type | so_has_subscription (const mbox_t &mbox, Method_Pointer) const noexcept |
| Check the presence of a subscription. More...
|
|
|
void | so_create_deadletter_subscription (const mbox_t &mbox, const std::type_index &msg_type, const event_handler_method_t &method, thread_safety_t thread_safety) |
| Create a subscription for a deadletter handler. More...
|
|
void | so_destroy_deadletter_subscription (const mbox_t &mbox, const std::type_index &msg_type) |
| Destroy a subscription for a deadletter handler. More...
|
|
template<typename Event_Handler > |
void | so_subscribe_deadletter_handler (const so_5::mbox_t &mbox, Event_Handler &&handler, thread_safety_t thread_safety=thread_safety_t::unsafe) |
| Create a subscription for deadletter handler for a specific message from a specific mbox. More...
|
|
template<typename Message > |
void | so_drop_deadletter_handler (const so_5::mbox_t &mbox) |
| Drops the subscription for deadletter handler. More...
|
|
template<typename Message > |
bool | so_has_deadletter_handler (const so_5::mbox_t &mbox) const noexcept |
| Checks the presence of deadletter handler for a message of a specific type from a specific mbox. More...
|
|
|
template<typename Message > |
void | so_set_delivery_filter (const mbox_t &mbox, delivery_filter_unique_ptr_t filter) |
| Set a delivery filter. More...
|
|
template<typename Lambda > |
void | so_set_delivery_filter (const mbox_t &mbox, Lambda &&lambda) |
| Set a delivery filter. More...
|
|
template<typename Lambda > |
void | so_set_delivery_filter_for_mutable_msg (const mbox_t &mbox, Lambda &&lambda) |
| Set a delivery filter for a mutable message. More...
|
|
template<typename Message > |
void | so_drop_delivery_filter (const mbox_t &mbox) noexcept |
| Drop a delivery filter. More...
|
|
|
priority_t | so_priority () const |
| Get the priority of the agent. More...
|
|
|
static void | call_push_event (agent_t &agent, const message_limit::control_block_t *limit, mbox_id_t mbox_id, std::type_index msg_type, const message_ref_t &message) |
| Push an event to the agent's event queue. More...
|
|
static agent_tuning_options_t | tuning_options () |
| Create tuning options object with default values. More...
|
|
template<typename Lambda > |
static custom_direct_mbox_factory_t | custom_direct_mbox_factory (Lambda &&lambda) |
| Helper for creation a custom direct mbox factory. More...
|
|
static execution_hint_t | so_create_execution_hint (execution_demand_t &demand) |
| Create execution hint for the specified demand. More...
|
|
template<typename Msg > |
static drop_indicator_t< Msg > | limit_then_drop (unsigned int limit) |
| A helper function for creating drop_indicator. More...
|
|
template<typename Msg > |
static abort_app_indicator_t< Msg > | limit_then_abort (unsigned int limit) |
| A helper function for creating abort_app_indicator. More...
|
|
template<typename M , typename L > |
static log_then_abort_app_indicator_t< M, L > | limit_then_abort (unsigned int limit, L lambda) |
| A helper function for creating log_then_abort_app_indicator. More...
|
|
template<typename Msg , typename Lambda > |
static redirect_indicator_t< Msg, Lambda > | limit_then_redirect (unsigned int limit, Lambda dest_getter) |
| A helper function for creating redirect_indicator. More...
|
|
template<typename Msg > |
static auto | limit_then_redirect (unsigned int limit, mbox_t destination) |
| A helper function for creating redirect_indicator. More...
|
|
template<typename Lambda , typename Arg = typename so_5::details::lambda_traits:: argument_type_if_lambda< Lambda >::type> |
static transform_indicator_t< Arg > | limit_then_transform (unsigned int limit, Lambda transformator) |
| A helper function for creating transform_indicator. More...
|
|
template<typename Source , typename Lambda > |
static transform_indicator_t< Source > | limit_then_transform (unsigned int limit, Lambda transformator) |
| A helper function for creating transform_indicator. More...
|
|
template<typename Msg , typename... Args> |
static transformed_message_t< Msg > | make_transformed (mbox_t mbox, Args &&... args) |
| Helper method for creating message transformation result. More...
|
|
|
void | destroy_all_subscriptions_and_filters () noexcept |
| Destroy all agent's subscriptions. More...
|
|
agent_ref_t | create_ref () |
| Make an agent reference. More...
|
|
void | ensure_operation_is_on_working_thread (const char *operation_name) const |
| Enables operation only if it is performed on agent's working thread. More...
|
|
void | drop_all_delivery_filters () noexcept |
| Drops all delivery filters. More...
|
|
void | do_set_delivery_filter (const mbox_t &mbox, const std::type_index &msg_type, delivery_filter_unique_ptr_t filter) |
| Set a delivery filter. More...
|
|
void | do_drop_delivery_filter (const mbox_t &mbox, const std::type_index &msg_type) noexcept |
| Drop a delivery filter. More...
|
|
void | do_change_agent_state (const state_t &state_to_be_set) |
| Perform actual operations related to state switch. More...
|
|
void | do_state_switch (const state_t &state_to_be_set) noexcept |
| Actual action for switching agent state. More...
|
|
void | return_to_default_state_if_possible () noexcept |
| Return agent to the default state. More...
|
|
bool | is_agent_deactivated () const noexcept |
| Is agent already deactivated. More...
|
|
|
void | bind_to_coop (coop_t &coop) |
| Bind agent to the cooperation. More...
|
|
void | shutdown_agent () noexcept |
| Agent shutdown deriver. More...
|
|
|
const message_limit::control_block_t * | detect_limit_for_message_type (const std::type_index &msg_type) |
| Detect limit for that message type. More...
|
|
void | do_drop_subscription (const mbox_t &mbox, const std::type_index &msg_type, const state_t &target_state) |
| Remove subscription for the state specified. More...
|
|
void | do_drop_subscription_for_all_states (const mbox_t &mbox, const std::type_index &msg_type) |
| Remove subscription for all states. More...
|
|
bool | do_check_subscription_presence (const mbox_t &mbox, const std::type_index &msg_type, const state_t &target_state) const noexcept |
| Check the presence of a subscription. More...
|
|
bool | do_check_deadletter_presence (const mbox_t &mbox, const std::type_index &msg_type) const noexcept |
| Check the presence of a deadletter handler. More...
|
|
|
void | push_event (const message_limit::control_block_t *limit, mbox_id_t mbox_id, std::type_index msg_type, const message_ref_t &message) |
| Push event into the event queue. More...
|
|
| atomic_refcounted_t (const atomic_refcounted_t &)=delete |
|
atomic_refcounted_t & | operator= (const atomic_refcounted_t &)=delete |
|
| atomic_refcounted_t () noexcept |
| Default constructor. More...
|
|
| ~atomic_refcounted_t () noexcept=default |
| Destructor. More...
|
|
void | inc_ref_count () noexcept |
| Increments reference count. More...
|
|
unsigned long | dec_ref_count () noexcept |
| Decrement reference count. More...
|
|
A base class for agents.
An agent in SObjctizer must be derived from the agent_t.
The base class provides various methods whose can be splitted into the following groups:
- methods for the interaction with SObjectizer;
- predefined hook-methods which are called during: cooperation registration, starting and stopping of an agent;
- methods for the message subscription and unsubscription;
- methods for working with an agent state;
Methods for the interaction with SObjectizer
Method so_5::agent_t::so_environment() serves for the access to the SObjectizer Environment (and, therefore, to all methods of the SObjectizer Environment). This method could be called immediatelly after the agent creation. This is because agent is bound to the SObjectizer Environment during the creation process.
Hook methods
The base class defines several hook-methods. Its default implementation do nothing.
The method agent_t::so_define_agent() is called just before agent will started by SObjectizer as a part of the agent registration process. It should be reimplemented for the initial subscription of the agent to messages.
There are two hook-methods related to important agent's lifetime events: agent_t::so_evt_start() and agent_t::so_evt_finish(). They are called by SObjectizer in next circumstances:
- method so_evt_start() is called when the agent is starting its work inside of SObjectizer. At that moment all agents are defined (all their methods agent_t::so_define_agent() have executed);
- method so_evt_finish() is called during the agent's cooperation deregistration just after agent processed the last pending event.
Methods so_evt_start() and so_evt_finish() are called by SObjectizer and user can just reimplement them to implement the agent-specific logic.
Message subscription and unsubscription methods
Any method with one of the following prototypes can be used as an event handler:
return_type evt_handler( mhood_t< Message > msg );
return_type evt_handler( const mhood_t< Message > & msg );
return_type evt_handler( const Message & msg );
return_type evt_handler( Message msg );
return_type evt_handler( mhood_t< Message > msg ) const;
return_type evt_handler( const mhood_t< Message > & msg ) const;
return_type evt_handler( const Message & msg ) const;
return_type evt_handler( Message msg ) const;
Where evt_handler
is a name of the event handler, Message
is a message type.
The class mhood_t is a wrapper on pointer to an instance of the Message
. It is very similar to std::unique_ptr
. The pointer to Message
can be a nullptr. It happens in case when the message has no actual data and servers just a signal about something.
Please note that handlers with the following prototypes can be used only for messages, not signals:
return_type evt_handler( const Message & msg );
return_type evt_handler( Message msg );
return_type evt_handler( const Message & msg ) const;
return_type evt_handler( Message msg ) const;
A subscription to the message is performed by the methods so_subscribe() and so_subscribe_self(). This method returns an instance of the so_5::subscription_bind_t which does all actual actions of the subscription process. This instance already knows agents and message mbox and uses the default agent state for the event subscription (binding to different state is also possible).
The presence of a subscription can be checked by so_has_subscription() method.
A subscription can be dropped (removed) by so_drop_subscription() and so_drop_subscription_for_all_states() methods.
Deadletter handlers subscription and unsubscription
Since v.5.5.21 SObjectizer supports deadletter handlers. Such handlers are called if there is no any ordinary event handler for a specific messages from a specific mbox.
Deadletter handler can be implemented by an agent method or by lambda function. Deadletter handler can have one of the following formats:
void evt_handler( mhood_t< Message > msg );
void return_type evt_handler( mhood_t< Message > msg ) const;
void return_type evt_handler( const mhood_t< Message > & msg );
void return_type evt_handler( const mhood_t< Message > & msg ) const;
void return_type evt_handler( const Message & msg );
void return_type evt_handler( const Message & msg ) const;
void return_type evt_handler( Message msg );
void return_type evt_handler( Message msg ) const;
Subscription for a deadletter handler can be created by so_subscribe_deadletter_handler() method.
The presence of a deadletter handler can be checked by so_has_deadletter_handler() method.
A deadletter can be dropped (removed) by so_drop_deadletter_handler() and so_drop_subscription_for_all_states() methods.
Methods for working with an agent state
The agent can change its state by his so_change_state() method.
An attempt to switch an agent to the state which belongs to the another agent is an error. If state is belong to the same agent there are no possibility to any run-time errors. In this case changing agent state is a very safe operation.
In some cases it is necessary to detect agent state switching. For example for application monitoring purposes. This can be done by "state listeners".
Any count of state listeners can be set for an agent. There are two methods for that:
Work thread identification
Since v.5.4.0 some operations for agent are enabled only on agent's work thread. They are:
- subscription management operations (creation or dropping);
- changing agent's state.
Work thread for an agent is defined as follows:
- before invocation of so_define_agent() the work thread is a thread on which agent is created (id of that thread is detected in agent's constructor);
- during cooperation registration the working thread is a thread on which so_environment::register_coop() is working;
- after successful agent registration the work thread for it is specified by the dispatcher.
- Note
- Some dispatchers could provide several work threads for an agent. In such case there would not be work thread id. And operations like changing agent state or creation of subscription would be prohibited after agent registration.
- Examples:
- so_5/adv_thread_pool_fifo/main.cpp, so_5/blinking_led/main.cpp, so_5/chameneos_prealloc_msgs/main.cpp, so_5/chameneos_simple/main.cpp, so_5/chstate/main.cpp, so_5/chstate_msg_tracing/main.cpp, so_5/coop_listener/main.cpp, so_5/coop_notification/main.cpp, so_5/coop_user_resources/main.cpp, so_5/custom_direct_mbox/main.cpp, so_5/custom_error_logger/main.cpp, so_5/custom_work_thread_factory/main.cpp, so_5/deadletter_handler/main.cpp, so_5/default_message_limits/main.cpp, so_5/delivery_filters/main.cpp, so_5/disp/main.cpp, so_5/dispatcher_for_children/main.cpp, so_5/dispatcher_hello/main.cpp, so_5/dispatcher_restarts/main.cpp, so_5/exception_logger/main.cpp, so_5/exception_reaction/main.cpp, so_5/hardwork_imit/main.cpp, so_5/hello_all/main.cpp, so_5/hello_delay/main.cpp, so_5/hello_evt_handler/main.cpp, so_5/hello_evt_lambda/main.cpp, so_5/hello_periodic/main.cpp, so_5/hello_world/main.cpp, so_5/hello_world_simple_not_mtsafe/main.cpp, so_5/intercom_statechart/main.cpp, so_5/machine_control/main.cpp, so_5/make_agent_ref/main.cpp, so_5/make_new_direct_mbox/main.cpp, so_5/make_pipeline/main.cpp, so_5/many_timers/main.cpp, so_5/modify_resend_as_immutable/main.cpp, so_5/mutable_msg_agents/main.cpp, so_5/named_dispatchers_layer/main.cpp, so_5/news_board/main.cpp, so_5/nohandler_msg_tracing/main.cpp, so_5/parent_coop/main.cpp, so_5/ping_pong/main.cpp, so_5/ping_pong_minimal/main.cpp, so_5/ping_pong_with_owner/main.cpp, so_5/prio_work_stealing/main.cpp, so_5/producer_consumer_mchain/main.cpp, so_5/queue_size_stats/main.cpp, so_5/redirect_and_transform/main.cpp, so_5/selective_msg_tracing/main.cpp, so_5/simple_message_deadline/main.cpp, so_5/state_deep_history/main.cpp, so_5/stop_guard/main.cpp, so_5/subscriptions/main.cpp, so_5/two_handlers/main.cpp, and so_5/wrapped_env_demo_2/main.cpp.