SObjectizer
5.5
|
Agent cooperation. More...
#include <coop.hpp>
Classes | |
struct | agent_with_disp_binder_t |
Information about agent and its dispatcher binding. More... | |
struct | resource_deleter_t |
Type of user resource deleter. More... | |
Public Member Functions | |
virtual | ~coop_t () |
SO_5_NODISCARD coop_handle_t | handle () noexcept |
Get handle for this coop. More... | |
SO_5_NODISCARD coop_id_t | id () const noexcept |
Get the ID of coop. More... | |
SO_5_NODISCARD environment_t & | environment () const noexcept |
Access to SO Environment for which cooperation is bound. More... | |
template<class Agent > | |
Agent * | add_agent (std::unique_ptr< Agent > agent) |
Add agent to cooperation. More... | |
template<class Agent > | |
Agent * | add_agent (std::unique_ptr< Agent > agent, disp_binder_shptr_t disp_binder) |
Add agent to the cooperation with the dispatcher binding. 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_shptr_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 noexcept |
Get agent count in the cooperation. More... | |
std::size_t | size () const noexcept |
Get agent count in the cooperation. More... | |
std::size_t | capacity () const noexcept |
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) noexcept |
Deregister the cooperation with the specified reason. More... | |
void | deregister_normally () noexcept |
Deregistr the cooperation normally. More... | |
Method for working with notificators. | |
template<typename Lambda > | |
void | add_reg_notificator (Lambda &¬ificator) |
Add notificator about cooperation registration event. More... | |
template<typename Lambda > | |
void | add_dereg_notificator (Lambda &¬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... | |
Exception reaction methods. | |
void | set_exception_reaction (exception_reaction_t value) noexcept |
Set exception reaction for that cooperation. More... | |
SO_5_NODISCARD exception_reaction_t | exception_reaction () const noexcept |
Get the current exception rection flag for that cooperation. More... | |
Protected Types | |
enum | registration_status_t { registration_status_t::coop_not_registered, registration_status_t::coop_registered, registration_status_t::coop_deregistering, registration_status_t::deregistration_in_final_stage } |
Registration status. More... | |
using | agent_array_t = std::vector< agent_with_disp_binder_t > |
Typedef for the agent information container. More... | |
using | resource_deleter_vector_t = std::vector< resource_deleter_t > |
Type of container for user resource deleters. More... | |
Protected Member Functions | |
coop_t (coop_id_t id, coop_handle_t parent, disp_binder_shptr_t coop_disp_binder, outliving_reference_t< environment_t > env) | |
Constructor. More... | |
void | increment_usage_count () noexcept |
Increment usage count for the coop. More... | |
void | decrement_usage_count () noexcept |
Decrement usage count for the coop. More... | |
void | add_child (coop_shptr_t child) |
Add a new child to the parent coop. More... | |
void | remove_child (coop_t &child) |
Remove a child from the parent coop. More... | |
template<typename Lambda > | |
void | for_each_child (Lambda &&lambda) const |
A helper method for doing some actions with children coops. More... | |
Protected Attributes | |
const coop_id_t | m_id |
Cooperation ID. More... | |
coop_handle_t | m_parent |
Parent coop. More... | |
disp_binder_shptr_t | m_coop_disp_binder |
Default agent to the dispatcher binder. More... | |
agent_array_t | m_agent_array |
Cooperation agents. More... | |
outliving_reference_t< environment_t > | m_env |
SObjectizer Environment for which cooperation is created. More... | |
atomic_counter_t | m_reference_count { 0l } |
Count for entities. 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_lock |
A lock for synchonization of some operations on coop. 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... | |
coop_shptr_t | m_first_child |
The head of list of children coops. More... | |
coop_shptr_t | m_prev_sibling |
The previous coop in sibling's chain. More... | |
coop_shptr_t | m_next_sibling |
The next coop in sibling's chain. More... | |
Private Member Functions | |
coop_t (const coop_t &)=delete | |
coop_t & | operator= (const coop_t &)=delete |
coop_t (coop_t &&)=delete | |
coop_t & | operator= (coop_t &&)=delete |
Friends | |
class | agent_t |
class | impl::coop_private_iface_t |
class | impl::coop_impl_t |
class | impl::coop_impl_t::registration_performer_t |
class | impl::coop_impl_t::deregistration_performer_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.
|
protected |
Typedef for the agent information container.
|
protected |
Type of container for user resource deleters.
|
strongprotected |
Registration status.
|
privatedelete |
|
privatedelete |
|
inlineprotected |
Constructor.
id | Cooperation ID. |
parent | Parent coop. |
coop_disp_binder | Default dispatcher binding. |
env | SObjectizer Environment. |
|
inlinevirtual |
|
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 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. |
|
inlineprotected |
Add a new child to the parent coop.
This method is called by child coop.
child | Child coop to be added. |
|
inline |
Add notificator about cooperation deregistration event.
|
inline |
Add notificator about cooperation registration event.
|
inlinenoexcept |
Get the capacity of vector for holding agents list.
|
inlineprotectednoexcept |
Decrement usage count for the coop.
Note that is usage count is become 0 then final deregistration actions will be initiated.
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.
|
inlinenoexcept |
Deregister the cooperation with the specified reason.
reason | Reason of cooperation deregistration. |
|
inlinenoexcept |
Deregistr the cooperation normally.
This method is just a shorthand for:
|
inlinenoexcept |
Access to SO Environment for which cooperation is bound.
|
inlinenoexcept |
Get the current exception rection flag for that cooperation.
It uses the following logic:
|
inlineprotected |
A helper method for doing some actions with children coops.
This method is intended to be used in derived classes where an access to m_first_child, m_prev_sibling and m_next_sibling from another coop object will be prohibited.
|
inlinenoexcept |
|
inlinenoexcept |
Get the ID of coop.
|
inlineprotectednoexcept |
Increment usage count for the coop.
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 |
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. |
|
inlinenoexcept |
Get agent count in the cooperation.
|
inlineprotected |
Remove a child from the parent coop.
This method is called by child coop.
child | Child coop to be removed. |
|
inline |
Reserve a space for vector for holding agents list.
This method can help avoid reallocations of agents list during filling the coop:
|
inlinenoexcept |
Set exception reaction for that cooperation.
This value will be used by agents and children cooperation if they use inherit_exception_reaction value.
|
inlinenoexcept |
|
inline |
Take a user resouce under cooperation control.
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
protected |
Cooperation agents.
|
protected |
Default agent to the dispatcher binder.
|
protected |
Notificators for deregistration event.
|
protected |
|
protected |
SObjectizer Environment for which cooperation is created.
|
protected |
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.
|
protected |
The head of list of children coops.
|
protected |
Cooperation ID.
|
protected |
A lock for synchonization of some operations on coop.
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.
Since v.5.6.0 this lock is also used for protecting changes of coop's status and sibling's chain.
|
protected |
The next coop in sibling's chain.
Can be nullptr if this coop is the last coop in the chain.
|
protected |
Parent coop.
|
protected |
The previous coop in sibling's chain.
Can be nullptr if this coop is the first coop in the chain.
|
protected |
Count for entities.
Since v.5.2.3 this counter includes:
|
protected |
Notificators for registration event.
|
protected |
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.
|
protected |
Container of user resource deleters.