SObjectizer
5.5
|
Agent cooperation. More...
#include <agent_coop.hpp>
Classes | |
struct | agent_with_disp_binder_t |
Information about agent and its dispatcher binding. More... | |
Public Member Functions | |
coop_t (nonempty_name_t name, disp_binder_unique_ptr_t coop_disp_binder, environment_t &env) | |
Constructor. More... | |
const std::string & | query_coop_name () const |
Get cooperation name. More... | |
template<class Agent > | |
Agent * | add_agent (std::unique_ptr< Agent > agent) |
Add agent to cooperation. More... | |
template<class Agent > | |
Agent * | add_agent (Agent *agent) |
Add agent to cooperation via raw pointer. More... | |
template<class Agent > | |
Agent * | add_agent (std::unique_ptr< Agent > agent, disp_binder_unique_ptr_t disp_binder) |
Add agent to the cooperation with the dispatcher binding. More... | |
template<class Agent > | |
Agent * | add_agent (Agent *agent, disp_binder_unique_ptr_t disp_binder) |
agent_context_t | make_agent_context () const |
Creation of instance of agent_context for tuning agent options. More... | |
adhoc_agent_definition_proxy_t | define_agent () |
Start definition of ad-hoc agent with default dispatcher binding. More... | |
adhoc_agent_definition_proxy_t | define_agent (agent_context_t ctx) |
Start definition of ad-hoc agent with default dispatcher binding and the custom agent tuning options. More... | |
adhoc_agent_definition_proxy_t | define_agent (disp_binder_unique_ptr_t binder) |
Start definition of ad-hoc agent with the specific dispatcher binder. More... | |
adhoc_agent_definition_proxy_t | define_agent (agent_context_t ctx, disp_binder_unique_ptr_t binder) |
Start definition of ad-hoc agent with the specific dispatcher binder and custom agent tuning options. More... | |
environment_t & | environment () const |
Access to SO Environment for which cooperation is bound. More... | |
template<class Agent , typename... Args> | |
Agent * | make_agent (Args &&... args) |
Helper method for simplification of agents creation. More... | |
template<class Agent , typename... Args> | |
Agent * | make_agent_with_binder (so_5::disp_binder_unique_ptr_t binder, Args &&... args) |
Helper method for simplification of agents creation and binding to the specified dispatcher. More... | |
std::size_t | query_agent_count () const |
Get agent count in the cooperation. More... | |
std::size_t | size () const |
Get agent count in the cooperation. More... | |
std::size_t | capacity () const |
Get the capacity of vector for holding agents list. More... | |
void | reserve (std::size_t v) |
Reserve a space for vector for holding agents list. More... | |
void | deregister (int reason) |
Deregister the cooperation with the specified reason. More... | |
void | deregister_normally () |
Deregistr the cooperation normally. More... | |
Methods for working with name of parent cooperation. | |
bool | has_parent_coop () const |
Does cooperation have parent cooperation? More... | |
void | set_parent_coop_name (nonempty_name_t name) |
Set name of the parent cooperation. More... | |
const std::string & | parent_coop_name () const |
Get name of the parent cooperation. More... | |
Method for working with notificators. | |
void | add_reg_notificator (const coop_reg_notificator_t ¬ificator) |
Add notificator about cooperation registration event. More... | |
void | add_dereg_notificator (const coop_dereg_notificator_t ¬ificator) |
Add notificator about cooperation deregistration event. More... | |
Method for working with user resources. | |
template<class T > | |
T * | take_under_control (std::unique_ptr< T > resource) |
Take a user resouce under cooperation control. More... | |
template<class T > | |
T * | take_under_control (T *resource) |
Take a user resouce under cooperation control. More... | |
Exception reaction methods. | |
void | set_exception_reaction (exception_reaction_t value) |
Set exception reaction for that cooperation. More... | |
exception_reaction_t | exception_reaction () const |
Get the current exception rection flag for that cooperation. More... | |
Static Public Member Functions | |
static void | destroy (coop_t *coop) |
Deleter for agent_coop. More... | |
static void | increment_usage_count (coop_t &coop) |
Internal SObjectizer method. More... | |
static void | decrement_usage_count (coop_t &coop) |
Internal SObjectizer method. More... | |
static void | call_final_deregister_coop (coop_t *coop) |
Internal SObjectizer method. More... | |
Protected Member Functions | |
virtual | ~coop_t () |
Private Types | |
enum | registration_status_t { registration_status_t::coop_not_registered, registration_status_t::coop_registered, registration_status_t::coop_deregistering } |
Registration status. More... | |
typedef std::vector< agent_with_disp_binder_t > | agent_array_t |
Typedef for the agent information container. More... | |
typedef std::function< void() > | resource_deleter_t |
Type of user resource deleter. More... | |
typedef std::vector< resource_deleter_t > | resource_deleter_vector_t |
Type of container for user resource deleters. More... | |
Private Member Functions | |
coop_t (const coop_t &)=delete | |
coop_t & | operator= (const coop_t &)=delete |
void | do_add_agent (const agent_ref_t &agent_ref) |
Add agent to cooperation. More... | |
void | do_add_agent (const agent_ref_t &agent_ref, disp_binder_unique_ptr_t disp_binder) |
Add agent to the cooperation with the dispatcher binding. More... | |
void | do_registration_specific_actions (coop_t *agent_coop) |
Perform all neccessary actions related to cooperation registration. More... | |
void | do_deregistration_specific_actions (coop_dereg_reason_t dereg_reason) |
Perform all necessary actions related to cooperation deregistration. More... | |
void | reorder_agents_with_respect_to_priorities () |
Rearrangement of agents in agents storage with respect to its priorities. More... | |
void | bind_agents_to_coop () |
Bind agents to the cooperation. More... | |
void | define_all_agents () |
Calls define_agent method for all cooperation agents. More... | |
void | bind_agents_to_disp () |
Bind agents to the dispatcher. More... | |
void | unbind_agents_from_disp (agent_array_t::iterator it) |
Unbind agent from the dispatcher. More... | |
void | shutdown_all_agents () |
Shutdown all agents as a part of cooperation deregistration. More... | |
void | increment_usage_count () |
Increment usage counter for this cooperation. More... | |
void | decrement_usage_count () |
void | final_deregister_coop () |
Do the final deregistration stage. More... | |
coop_t * | parent_coop_ptr () const |
Get pointer to the parent cooperation. More... | |
coop_reg_notificators_container_ref_t | reg_notificators () const |
Get registration notificators. More... | |
coop_dereg_notificators_container_ref_t | dereg_notificators () const |
Get deregistration notificators. More... | |
void | delete_user_resources () |
Delete all user resources. More... | |
const coop_dereg_reason_t & | dereg_reason () const |
Get deregistration reason. More... | |
Private Attributes | |
const std::string | m_coop_name |
Cooperation name. More... | |
disp_binder_ref_t | m_coop_disp_binder |
Default agent to the dispatcher binder. More... | |
agent_array_t | m_agent_array |
Cooperation agents. More... | |
environment_t & | m_env |
SObjectizer Environment for which cooperation is created. More... | |
atomic_counter_t | m_reference_count |
Count for entities. More... | |
std::string | m_parent_coop_name |
Name of the parent cooperation. More... | |
coop_t * | m_parent_coop_ptr |
Pointer to parent cooperation. More... | |
coop_reg_notificators_container_ref_t | m_reg_notificators |
Notificators for registration event. More... | |
coop_dereg_notificators_container_ref_t | m_dereg_notificators |
Notificators for deregistration event. More... | |
std::mutex | m_binding_lock |
A lock for synchonization of evt_start events. More... | |
registration_status_t | m_registration_status |
The registration status of cooperation. More... | |
resource_deleter_vector_t | m_resource_deleters |
Container of user resource deleters. More... | |
coop_dereg_reason_t | m_dereg_reason |
Deregistration reason. More... | |
exception_reaction_t | m_exception_reaction |
A reaction to non-handled exception. More... | |
Friends | |
class | agent_t |
class | impl::agent_core_t |
class | impl::coop_private_iface_t |
Agent cooperation.
The main purpose of the cooperation is the introducing of several agents into SObjectizer as a single unit. A cooperation should be registered.
For the cooperation to be successfuly registered all of its agents must successfuly pass registration steps (so-define, bind to the dispatcher). If at least one agent out of this cooperation fails to pass any of mentioned steps, the cooperation will not be registered and all of agents will run procedures opposite to registration steps (unbind from the dispatcher, so-undefine) which had been successfuly taken for the particulary agent in the reverse order.
Agents are added to the cooperation by the add_agent() method.
After addition to the cooperation the cooperation takes care about the agent lifetime.
|
private |
Typedef for the agent information container.
|
private |
Type of user resource deleter.
|
private |
Type of container for user resource deleters.
|
strongprivate |
Registration status.
|
privatedelete |
|
protectedvirtual |
so_5::coop_t::coop_t | ( | nonempty_name_t | name, |
disp_binder_unique_ptr_t | coop_disp_binder, | ||
environment_t & | env | ||
) |
Constructor.
name | Cooperation name. |
coop_disp_binder | Default dispatcher binding. |
env | SObjectizer Environment. |
|
inline |
Add agent to cooperation.
Cooperation takes care about agent lifetime.
Default dispatcher binding is used for the agent.
agent | Agent. |
|
inline |
Add agent to cooperation via raw pointer.
Cooperation takes care about agent lifetime.
Default dispatcher binding is used for the agent.
agent | Agent. |
|
inline |
Add agent to the cooperation with the dispatcher binding.
Instead of the default dispatcher binding the disp_binder is used for this agent during the cooperation registration.
agent | Agent. |
disp_binder | Agent to dispatcher binder. |
|
inline |
Add agent to the cooperation via raw pointer and with the dispatcher binding.
Instead of the default dispatcher binding the disp_binder is used for this agent during the cooperation registration.
agent | Agent. |
disp_binder | Agent to dispatcher binder. |
void so_5::coop_t::add_dereg_notificator | ( | const coop_dereg_notificator_t & | notificator | ) |
Add notificator about cooperation deregistration event.
void so_5::coop_t::add_reg_notificator | ( | const coop_reg_notificator_t & | notificator | ) |
Add notificator about cooperation registration event.
|
private |
Bind agents to the cooperation.
|
private |
Bind agents to the dispatcher.
|
inlinestatic |
Internal SObjectizer method.
Initiate a final deregistration stage.
|
inline |
Get the capacity of vector for holding agents list.
|
inlinestatic |
Internal SObjectizer method.
Informs cooperation about full finishing of agent's or child cooperation work.
|
private |
Process signal about finished work of an agent or child cooperation.
Cooperation deregistration is a long process. All agents process events out of their queues. When an agent detects that no more events in its queue it informs the cooperation about this.
When cooperation detects that all agents have finished their work it initiates the agent's destruction.
Since v.5.2.3 this method used not only for agents of cooperation but and for children cooperations. Because final step of cooperation deregistration could be initiated only when all children cooperations are deregistered and destroyed.
|
inline |
Start definition of ad-hoc agent with default dispatcher binding.
Usage sample:
|
inline |
Start definition of ad-hoc agent with default dispatcher binding and the custom agent tuning options.
Usage sample:
ctx | Agent tuning options. |
|
inline |
Start definition of ad-hoc agent with the specific dispatcher binder.
Usage sample:
binder | A binder to the dispatcher. |
|
inline |
Start definition of ad-hoc agent with the specific dispatcher binder and custom agent tuning options.
Usage sample:
ctx | Agent tuning options. |
binder | A binder to the dispatcher. |
|
private |
Calls define_agent method for all cooperation agents.
|
private |
Delete all user resources.
|
private |
Get deregistration notificators.
|
private |
Get deregistration reason.
void so_5::coop_t::deregister | ( | int | reason | ) |
Deregister the cooperation with the specified reason.
reason | Reason of cooperation deregistration. |
|
inline |
Deregistr the cooperation normally.
|
static |
Deleter for agent_coop.
|
private |
Add agent to cooperation.
Cooperation takes care about agent lifetime.
Default dispatcher binding is used for the agent.
|
private |
Add agent to the cooperation with the dispatcher binding.
Instead of the default dispatcher binding the disp_binder is used for this agent during the cooperation registration.
agent_ref | Agent. |
disp_binder | Agent to dispatcher binder. |
|
private |
Perform all necessary actions related to cooperation deregistration.
dereg_reason | Deregistration reason. |
|
private |
Perform all neccessary actions related to cooperation registration.
agent_coop | Pointer to the parent cooperation. Contains nullptr if there is no parent cooperation. |
|
inline |
Access to SO Environment for which cooperation is bound.
exception_reaction_t so_5::coop_t::exception_reaction | ( | ) | const |
Get the current exception rection flag for that cooperation.
It uses the following logic:
|
private |
Do the final deregistration stage.
bool so_5::coop_t::has_parent_coop | ( | ) | const |
Does cooperation have parent cooperation?
|
inlinestatic |
Internal SObjectizer method.
Informs cooperation that it is used by yet another entity.
|
private |
Increment usage counter for this cooperation.
In v.5.2.3 the counter m_reference_count is used to reflect count of references to the cooperation. There are the following entities who can refer to cooperation:
|
inline |
Helper method for simplification of agents creation.
Agent | type of agent to be created. |
Args | type of parameters list for agent constructor. |
|
inline |
Creation of instance of agent_context for tuning agent options.
|
inline |
Helper method for simplification of agents creation and binding to the specified dispatcher.
Agent | type of agent to be created. |
Args | type of parameters list for agent constructor. |
binder | A dispatcher binder for the new agent. |
args | Arguments to be passed to the agent's constructor. |
const std::string & so_5::coop_t::parent_coop_name | ( | ) | const |
Get name of the parent cooperation.
exception_t | if the parent cooperation name is not set. |
|
private |
Get pointer to the parent cooperation.
nullptr | if there is no parent cooperation. |
|
inline |
Get agent count in the cooperation.
const std::string & so_5::coop_t::query_coop_name | ( | ) | const |
Get cooperation name.
|
private |
Get registration notificators.
|
private |
Rearrangement of agents in agents storage with respect to its priorities.
This step is necessary to handle agents with high priorities before agents with low priorities.
|
inline |
Reserve a space for vector for holding agents list.
This method can help avoid reallocations of agents list during filling the coop:
void so_5::coop_t::set_exception_reaction | ( | exception_reaction_t | value | ) |
Set exception reaction for that cooperation.
This value will be used by agents and children cooperation if they use inherit_exception_reaction value.
void so_5::coop_t::set_parent_coop_name | ( | nonempty_name_t | name | ) |
Set name of the parent cooperation.
|
private |
Shutdown all agents as a part of cooperation deregistration.
An exception from agent_t::shutdown_agent() leads to call to abort().
|
inline |
|
inline |
Take a user resouce under cooperation control.
|
inline |
Take a user resouce under cooperation control.
|
inlineprivate |
Unbind agent from the dispatcher.
Unbinds all agents in range [m_agent_array.begin(), it).
it | Right border of the processing range. |
|
friend |
|
friend |
|
friend |
|
private |
Cooperation agents.
|
private |
A lock for synchonization of evt_start events.
A new way of handling coop registration was introduced in v.5.5.8. Agents from the coop cannot start its work before finish of main coop registration actions (expecialy before end of such important step as binding agents to dispatchers). But some agents could receive evt_start event before end of agents binding step. Those agents will be stopped on this lock.
Coop acquires this lock before agents binding step and releases just after that. Every agent tries to acquire it during handling of evt_start. If lock is belong to coop then an agent will be stopped until the lock will be released.
|
private |
Default agent to the dispatcher binder.
|
private |
Cooperation name.
|
private |
Notificators for deregistration event.
|
private |
Deregistration reason.
Receives actual value only in do_deregistration_specific_actions().
|
private |
SObjectizer Environment for which cooperation is created.
|
private |
A reaction to non-handled exception.
By default inherit_exception_reaction is used. It means that actual exception reaction should be provided by parent coop or by SO Environment.
|
private |
Name of the parent cooperation.
Empty value means than there is no parent cooperation.
|
private |
Pointer to parent cooperation.
Gets the value only if there is the parent cooperation and cooperation itself is registered successfully.
|
private |
Count for entities.
Since v.5.2.3 this counter includes:
|
private |
Notificators for registration event.
|
private |
The registration status of cooperation.
By default cooperation has NOT_REGISTERED status. It is changed to REGISTERED after successfull completion of all registration-specific actions.
And then changed to DEREGISTERING when m_reference_count becames zero and final deregistration demand would be put to deregistration thread.
|
private |
Container of user resource deleters.