SObjectizer  5.5
Public Member Functions | Private Attributes | List of all members
so_5::adhoc_agent_wrapper_t Class Reference

Special agent class which would be used as wrapper for ad-hoc agents. More...

#include <adhoc_agent_wrapper.hpp>

Inheritance diagram for so_5::adhoc_agent_wrapper_t:
so_5::agent_t so_5::atomic_refcounted_t so_5::message_limit::message_limit_methods_mixin_t

Public Member Functions

 adhoc_agent_wrapper_t (agent_context_t ctx)
 
void set_on_evt_start (std::function< void() > handler)
 Set function for reaction on work start. More...
 
void set_on_evt_finish (std::function< void() > handler)
 Set function for reaction on work finish. More...
 
void set_exception_reaction (exception_reaction_t reaction) SO_5_NOEXCEPT
 Set reaction for non-handled exceptions. More...
 
virtual void so_evt_start () override
 Hook on agent start inside SObjectizer. More...
 
virtual void so_evt_finish () override
 Hook of agent finish in SObjectizer. More...
 
virtual exception_reaction_t so_exception_reaction () const override
 A reaction from SObjectizer to an exception from agent's event. More...
 
- Public Member Functions inherited from so_5::agent_t
 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_tself_ptr () const
 Get the raw pointer of itself. More...
 
agent_tself_ptr ()
 
const state_tso_current_state () const
 Access to the current agent state. More...
 
bool so_is_active_state (const state_t &state_to_check) const
 Is a state activated? More...
 
const std::string & so_coop_name () const
 Name of the agent's cooperation. 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...
 
void so_switch_to_awaiting_deregistration_state ()
 Switching agent to special state in case of unhandled exception. More...
 
const mbox_tso_direct_mbox () const
 Get the agent's direct mbox. More...
 
environment_tso_environment () const
 Access to the SObjectizer Environment which this agent is belong. More...
 
void so_bind_to_dispatcher (event_queue_t &queue)
 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...
 
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)
 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< 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, signal_indicator_t< Message >())
 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< 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, signal_indicator_t< Message >())
 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< 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, signal_indicator_t< Message >())
 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 SO_5_NOEXCEPT
 Check the presence of a subscription. More...
 
template<class Message >
bool so_has_subscription (const mbox_t &mbox) const SO_5_NOEXCEPT
 Check the presence of a subscription in the default_state. More...
 
template<typename Method_Pointer >
std::enable_if< details::is_agent_method_pointer< Method_Pointer >::value, bool >::type so_has_subscription (const mbox_t &mbox, const state_t &target_state, Method_Pointer) const SO_5_NOEXCEPT
 Check the presence of a subscription. More...
 
template<typename Method_Pointer >
std::enable_if< details::is_agent_method_pointer< Method_Pointer >::value, bool >::type so_has_subscription (const mbox_t &mbox, Method_Pointer) const SO_5_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 SO_5_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 Message >
void so_drop_delivery_filter (const mbox_t &mbox) SO_5_NOEXCEPT
 Drop a delivery filter. More...
 
priority_t so_priority () const
 Get the priority of the agent. More...
 
void so_change_state (const state_t &new_state)
 Method changes state. More...
 
void ensure_binding_finished ()
 Ensures that all agents from cooperation are bound to dispatchers. More...
 

Private Attributes

std::function< void() > m_on_start
 
std::function< void() > m_on_finish
 
exception_reaction_t m_exception_reaction
 

Additional Inherited Members

- Public Types inherited from so_5::agent_t
using context_t = so_5::agent_context_t
 Short alias for agent_context. More...
 
using state_t = so_5::state_t
 Short alias for so_5::state_t. More...
 
template<typename T >
using mhood_t = so_5::mhood_t< T >
 Short alias for so_5::mhood_t. More...
 
template<typename T >
using mutable_mhood_t = so_5::mutable_mhood_t< T >
 Short alias for so_5::mutable_mhood_t. More...
 
using initial_substate_of = so_5::initial_substate_of
 Short alias for so_5::initial_substate_of. More...
 
using substate_of = so_5::substate_of
 Short alias for so_5::substate_of. More...
 
- Static Public Member Functions inherited from so_5::agent_t
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 void call_push_service_request (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 service request to the agent's event queue. More...
 
static agent_tuning_options_t tuning_options ()
 Create tuning options object with default values. More...
 
static execution_hint_t so_create_execution_hint (execution_demand_t &demand)
 Create execution hint for the specified demand. More...
 
static void demand_handler_on_start (current_thread_id_t working_thread_id, execution_demand_t &d)
 Calls so_evt_start method for agent. More...
 
static demand_handler_pfn_t get_demand_handler_on_start_ptr () SO_5_NOEXCEPT
 
static void demand_handler_on_finish (current_thread_id_t working_thread_id, execution_demand_t &d)
 Calls so_evt_finish method for agent. More...
 
static demand_handler_pfn_t get_demand_handler_on_finish_ptr () SO_5_NOEXCEPT
 
static void demand_handler_on_message (current_thread_id_t working_thread_id, execution_demand_t &d)
 Calls event handler for message. More...
 
static demand_handler_pfn_t get_demand_handler_on_message_ptr () SO_5_NOEXCEPT
 
static void demand_handler_on_service_request (current_thread_id_t working_thread_id, execution_demand_t &d)
 Calls request handler for message. More...
 
static demand_handler_pfn_t get_service_request_handler_on_message_ptr () SO_5_NOEXCEPT
 
static void demand_handler_on_enveloped_msg (current_thread_id_t working_thread_id, execution_demand_t &d)
 Handles the enveloped message. More...
 
static demand_handler_pfn_t get_demand_handler_on_enveloped_msg_ptr () SO_5_NOEXCEPT
 
- Static Public Member Functions inherited from so_5::message_limit::message_limit_methods_mixin_t
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 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...
 
- Static Public Attributes inherited from so_5::agent_t
static const state_t::history_t shallow_history
 Short alias for so_5::state_t::history_t::shallow. More...
 
static const state_t::history_t deep_history
 Short alias for so_5::state_t::history_t::deep. More...
 
- Protected Member Functions inherited from so_5::agent_t
void so_initiate_agent_definition ()
 A correct initiation of so_define_agent method call. More...
 
virtual void so_define_agent ()
 Hook on define agent for SObjectizer. More...
 
bool so_was_defined () const
 Is method define_agent already called? More...
 
state_t so_make_state ()
 Helper method for creation of anonymous state object. More...
 
state_t so_make_state (std::string name)
 Helper method for creation of named state object. More...
 
const state_tso_default_state () const
 Access to the agent's default state. More...
 

Detailed Description

Special agent class which would be used as wrapper for ad-hoc agents.

Since
v.5.3.0
Note
The presence and usefulness of this class is based on the fact that it is not necessary to subscribe agent exactly in so_define_agent() method. The current implementation of agents and SObjectizer Run-Time allows to subscribe and unsubscribe agent in any place and at any time.

Constructor & Destructor Documentation

◆ adhoc_agent_wrapper_t()

so_5::adhoc_agent_wrapper_t::adhoc_agent_wrapper_t ( agent_context_t  ctx)
inline

Member Function Documentation

◆ set_exception_reaction()

void so_5::adhoc_agent_wrapper_t::set_exception_reaction ( exception_reaction_t  reaction)
inline

Set reaction for non-handled exceptions.

◆ set_on_evt_finish()

void so_5::adhoc_agent_wrapper_t::set_on_evt_finish ( std::function< void() >  handler)
inline

Set function for reaction on work finish.

◆ set_on_evt_start()

void so_5::adhoc_agent_wrapper_t::set_on_evt_start ( std::function< void() >  handler)
inline

Set function for reaction on work start.

◆ so_evt_finish()

virtual void so_5::adhoc_agent_wrapper_t::so_evt_finish ( )
inlineoverridevirtual

Hook of agent finish in SObjectizer.

It is guaranteed that this method will be called last just before deattaching agent from it's working thread.

This method should be used to perform some cleanup actions on it's working thread.

class a_sample_t : public so_5::agent_t
{
// ...
virtual void
// ...
};
a_sample_t::so_evt_finish()
{
std::cout << "last agent activity";
if( so_current_state() == m_db_error_happened )
{
// Delete the DB connection on the same thread where
// connection was established and where some
// error happened.
m_db.release();
}
}

Reimplemented from so_5::agent_t.

◆ so_evt_start()

virtual void so_5::adhoc_agent_wrapper_t::so_evt_start ( )
inlineoverridevirtual

Hook on agent start inside SObjectizer.

It is guaranteed that this method will be called first just after end of the cooperation registration process.

During cooperation registration agent is bound to some working thread. And the first method which is called for the agent on that working thread context is this method.

class a_sample_t : public so_5::agent_t
{
// ...
virtual void
// ...
};
a_sample_t::so_evt_start()
{
std::cout << "first agent action on bound dispatcher" << std::endl;
... // Some application logic actions.
}

Reimplemented from so_5::agent_t.

◆ so_exception_reaction()

virtual exception_reaction_t so_5::adhoc_agent_wrapper_t::so_exception_reaction ( ) const
inlineoverridevirtual

A reaction from SObjectizer to an exception from agent's event.

Since
v.5.2.3

If an exception is going out from agent's event it will be caught by SObjectizer. Then SObjectizer will call this method and perform some actions in dependence of return value.

Note
Since v.5.3.0 default implementation calls coop_t::exception_reaction() for agent's cooperation object.

Reimplemented from so_5::agent_t.

Member Data Documentation

◆ m_exception_reaction

exception_reaction_t so_5::adhoc_agent_wrapper_t::m_exception_reaction
private

◆ m_on_finish

std::function< void() > so_5::adhoc_agent_wrapper_t::m_on_finish
private

◆ m_on_start

std::function< void() > so_5::adhoc_agent_wrapper_t::m_on_start
private

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