SlideShare una empresa de Scribd logo
1 de 40
Descargar para leer sin conexión
Dive into SObjectizer-5.5
SObjectizer Team, Jan 2016
Third Part: More About Coops
(at v.5.5.15)
This is the next part of the serie of presentations with deep
introduction into features of SObjectizer-5.5.
This part is dedicated to such important feature as
cooperations. In particular:
● parent-child relationship;
● resource lifetime management;
● reg/dereg notificators.
SObjectizer Team, Jan 2016
Parent-Child Relationship
SObjectizer Team, Jan 2016
Cooperation (or coop in short) is a way for binding several
tightly related agents into a whole entity.
Coop is registered in SObjectizer Environment in a
transactional manner: all agents from the cooperation must
be registered successfully or no one of them.
When a coop is being deregistered all its agents are
deregistered and destroyed at the same time.
SObjectizer Team, Jan 2016
There could be agents which require creation of additional
coop(s) for performing their work.
Let's imagine an agent which is responsible of receiving and
processing of some requests.
Payment requests, for example.
SObjectizer Team, Jan 2016
Processing of each payment request requires several
operations:
● checking payments parameters,
● checking the operation risks,
● checking the availability of funds
● and so on...
The request receiver could do those actions for every
payment by itself. But this will lead to very complicated logic
of request receiver.
SObjectizer Team, Jan 2016
There is much simpler approach: delegation of processing of
one request to a separate processor agent.
In that case the request receiver will only receive new
requests and create new coops with actual request
processors for each new request.
Receiver and processor agents will have more simple logic
and it is good.
But there will be a new question...
SObjectizer Team, Jan 2016
Who and how will control lifetime of all cooperations with
request processors?
SObjectizer Team, Jan 2016
Very simple view of that problem:
Someone could call deregister_coop() for request
receiver’s coop. As result all coops with request
processors must be deregistered too.
But how it could be done?
SObjectizer Team, Jan 2016
Such feature as child coop is coming into play here.
SObjectizer Team, Jan 2016
SObjectizer-5 allows to mark new coop as a child of any
existing coop.
In this case SObjectizer guarantees that all children coops
will be deregistered and destroyed before its parent coop.
SObjectizer Team, Jan 2016
It means that if we have, for example, a parent coop with
name “manager” and a child coop with name
“request_receiver” and do call:
env.deregister_coop( "manager", so_5::dereg_reason::normal );
Then SObjectizer-5 will deregister and destroy
“request_receiver” and only then “manager” coop will be
deregistered and destroyed.
SObjectizer Team, Jan 2016
Child coop could have its own child coops too.
It means that “request_receiver” coop could have any
number of child coops like “request_processor_1”,
“request_processor_2” and so on.
All of them will be automatically destroyed when top-level
parent coop “manager” is deregistered.
SObjectizer Team, Jan 2016
Parent-child relationship between coops allows to build
coops hierarchies: a top-level coop creates child coops,
those create its own child coops and so on.
If a top-level coop is being deregistered by some reason
then all its child coops (and children of children and so on)
will be deregistered too. A programmer could no takes care
about this.
SObjectizer Team, Jan 2016
There are several ways to make a child coop...
SObjectizer Team, Jan 2016
The first way, the oldest and verbose:
auto coop = env.create_coop( "request_processor_1" );
coop->set_parent_coop_name( "request_receiver" );
... // Filling the coop.
env.register_coop( std::move( coop ) );
Coop “request_processor_1” will be a child for coop
“request_receiver”.
SObjectizer Team, Jan 2016
The second one applicable if there is an agent from the
parent coop:
void parent_agent::make_new_coop()
{
auto coop = so_5::create_child_coop( *this, "request_processor_1" );
... // Filling the coop.
so_environment().register_coop( std::move( coop ) );
}
Name of the parent coop will be set automatically.
SObjectizer Team, Jan 2016
The third one is available since v.5.5.5:
void parent_agent::make_new_coop()
{
so_5::introduce_child_coop( *this, "request_processor_1",
[]( so_5::coop_t & coop ) {
... // Filling the coop.
} );
}
Name of the parent coop will be set automatically.
SObjectizer Team, Jan 2016
Resource Lifetime Management
SObjectizer Team, Jan 2016
Sometimes it is necessary to manage lifetime of some
resources.
For example all agents from your coop should have a
reference to the same DB connection object.
If this connection object is allocated dynamically you can
pass a shared_ptr to every agent's constructor. Something
like:
SObjectizer Team, Jan 2016
class first_agent : public so_5::agent_t { ...
public :
first_agent( context_t ctx, std::shared_ptr< db_connection > conn, ... );
...
private :
std::shared_ptr< db_connection > connection_;
};
class second_agent : public so_5::agent_t { ...
public :
second_agent( context_t ctx, std::shared_ptr< db_connection > conn, ... );
...
private :
std::shared_ptr< db_connection > connection_;
};
env.introduce_coop( []( so_5::coop_t & coop ) {
std::shared_ptr< db_connection > connection = connect_to_db(...);
coop.make_agent< first_agent >( connection, ... );
coop.make_agent< second_agent >( connection, ... );
...
} );
SObjectizer Team, Jan 2016
In such case you make tight coupling between application
domain logic of your agents and DB connection lifetime
management.
SObjectizer Team, Jan 2016
What if this lifetime management need to be changed in the
future? What if connection object is controlled by someone
else and you have a simple reference to it (not shared_ptr)?
You will need to do some rewriting...
SObjectizer Team, Jan 2016
class first_agent : public so_5::agent_t { ...
public :
first_agent( context_t ctx, db_connection & conn, ... ); // The constructor has to be changed.
...
private :
db_connection & connection_; // Declaration of the member has to be changed.
};
class second_agent : public so_5::agent_t { ...
public :
second_agent( context_t ctx, db_connection & conn, ... ); // The constructor has to be changed.
...
private :
db_connection & connection_; // Declaration of the member has to be changed.
};
...
db_connection & conn = receive_connection_from_somewhere();
env.introduce_coop( [&conn]( so_5::coop_t & coop ) {
coop.make_agent< first_agent >( conn, ... );
coop.make_agent< second_agent >( conn, ... );
...
} );
SObjectizer Team, Jan 2016
SObjectizer-5 has a tool for decoupling resource lifetime
management from agent's domain-specific logic.
This is coop_t::take_under_control().
Method coop_t::take_under_control() allows to pass
dynamically allocated object under the control of the
cooperation.
The object placed under control will be deallocated only after
destroying all agents of the coop.
SObjectizer Team, Jan 2016
The behaviour of take_under_control() allows to use the
reference to controlled object even from agent's destructor...
SObjectizer Team, Jan 2016
class request_processor : public so_5::agent_t
{
public :
request_processor( context_t ctx, db_connection & connection );
~request_processor() {
if( !commited() )
// Assume that this reference is still valid.
connection_.commit();
}
...
private :
db_connection & connection_;
};
...
env.introduce_coop( []( so_5::coop_t & coop )
{
// Place DB connection under the control of the cooperation.
auto & connection = *coop.take_under_control(create_connection(...));
// Reference to DB connection will be valid even in requests_processor's destructor.
coop->make_agent< request_processor >( connection );
...
} );
SObjectizer Team, Jan 2016
Parent-child relationship could also be used for resource
lifetime management...
SObjectizer Team, Jan 2016
class request_receiver : public so_5::agent_t
{
std::unique_ptr< db_connection > connection_;
...
public :
virtual void so_evt_start() override {
connection_ = make_db_connection(...);
...
}
...
private :
void evt_new_request( const request & evt ) {
// New request handler must be created.
so_5::introduce_child_coop( *this, [=]( so_5::coop_t & coop ) {
// Reference to DB connection will be valid even in requests_processor's destructor.
// It is because agents from child cooperation will be destroyed before any of
// agents from the parent cooperation.
coop->make_agent< request_processor >( connection );
...
} );
}
};
SObjectizer Team, Jan 2016
Reg/Dereg Notificators
SObjectizer Team, Jan 2016
It is not easy to detect precise moments when a coop is
completely registered or completely deregistered.
The biggest problem is a detection of complete coop
deregistration.
It is because calling to environment_t::deregister_coop() just
initiates coop deregistration process. But the entire process
of deregistration could take a long time.
SObjectizer Team, Jan 2016
To simplify that there are such things as registration and
deregistration notificators.
Notificator could be bound to a coop and it will be called
when coop registration/deregistration process is finished.
SObjectizer Team, Jan 2016
The simplest reg/dereg notificators:
env.introduce_coop( []( so_5::coop_t & coop ) {
coop.add_reg_notificator(
[]( so_5::environment_t &, const std::string & name ) {
std::cout << "registered: " << name << std::endl;
} );
coop.add_dereg_notificator(
[]( so_5::environment_t &,
const std::string & name,
const so_5::coop_dereg_reason_t & ) {
std::cout << "deregistered: " << name << std::endl;
} );
...
} );
Name of coop will be printed to stdout on coop registration
and deregistration.
SObjectizer Team, Jan 2016
Usually reg/dereg notifications are used for sending
messages to some mboxes.
Because this scenario is widely used there are two ready-to-
use notificators in SObjectizer-5.5.
They are created by make_coop_reg_notificator() and
make_coop_dereg_notificator() functions...
SObjectizer Team, Jan 2016
The standard notificators:
auto notify_mbox = env.create_local_mbox();
env.introduce_coop( [&]( so_5::coop_t & coop ) {
// An instance of so_5::msg_coop_registered will be sent to notify_mbox
// when the cooperation is registered.
coop.add_reg_notificator( so_5::make_coop_reg_notificator( notify_mbox ) );
// An instance of so_5::msg_coop_deregistered will be sent to
// notify_mbox when the cooperation is deregistered.
coop.add_dereg_notificator( so_5::make_coop_dereg_notificator( notify_mbox ) );
...
} );
SObjectizer Team, Jan 2016
Coop dereg notificators can be used for implementation of
Erlang-like supervisors.
For example, request receiver could receive notification
about deregistration of child coops and restart them if they
fail...
SObjectizer Team, Jan 2016
Very simple way of controlling a child (1/2):
class request_receiver : public so_5::agent_t
{
public :
virtual void so_define_agent() override {
// msg_coop_deregistered must be handled.
so_subscribe_self().event( &request_receiver::evt_child_finished );
...
}
...
private :
void evt_new_request( const request & req ) {
auto child_name = store_request_info( req );
so_5::introduce_child_coop( child_name,
[&]( so_5::coop_t & coop ) {
... // Filling the coop with agents.
// Dereg notificator is necessary to receive info about child disappearance.
SObjectizer Team, Jan 2016
Very simple way of controlling a child (2/2):
// Standard notificator will be used.
coop.add_dereg_notificator(
// We want a message to request_receiver direct_mbox.
so_5::make_coop_dereg_notificator( so_direct_mbox() ) );
} );
...
}
void evt_child_finished( const so_5::msg_coop_deregistered & evt ) {
// If child cooperation failed its dereg reason will differ
// from the normal value.
if( so_5::dereg_reason::normal != evt.m_reason.reason() )
recreate_child_coop( evt.m_coop_name );
else
remove_request_info( evt.m_coop_name );
}
...
};
SObjectizer Team, Jan 2016
That is almost all what it needs to be known about agent
coops.
There are yet more issues like coop deregistration reasons
and exception reaction inheritance…
But those topics will be covered in the next parts of “Dive
into SObjectizer-5.5”
SObjectizer Team, Jan 2016
Additional Information:
Project’s home: http://sourceforge.net/projects/sobjectizer
Documentation: http://sourceforge.net/p/sobjectizer/wiki/
Forum: http://sourceforge.net/p/sobjectizer/discussion/
Google-group: https://groups.google.com/forum/#!forum/sobjectizer
GitHub mirror: https://github.com/masterspline/SObjectizer

Más contenido relacionado

La actualidad más candente

arataga. SObjectizer and RESTinio in action: a real-world example
arataga. SObjectizer and RESTinio in action: a real-world examplearataga. SObjectizer and RESTinio in action: a real-world example
arataga. SObjectizer and RESTinio in action: a real-world exampleYauheni Akhotnikau
 
Date Processing Attracts Bugs or 77 Defects in Qt 6
Date Processing Attracts Bugs or 77 Defects in Qt 6Date Processing Attracts Bugs or 77 Defects in Qt 6
Date Processing Attracts Bugs or 77 Defects in Qt 6Andrey Karpov
 
2. Design patterns. part #2
2. Design patterns. part #22. Design patterns. part #2
2. Design patterns. part #2Leonid Maslov
 
What's New In Python 2.6
What's New In Python 2.6What's New In Python 2.6
What's New In Python 2.6Richard Jones
 
PVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd CheckPVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd CheckAndrey Karpov
 
Testing RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkTesting RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkMicha Kops
 
The Little Unicorn That Could
The Little Unicorn That CouldThe Little Unicorn That Could
The Little Unicorn That CouldPVS-Studio
 
Creating a Java EE 7 Websocket Chat Application
Creating a Java EE 7 Websocket Chat ApplicationCreating a Java EE 7 Websocket Chat Application
Creating a Java EE 7 Websocket Chat ApplicationMicha Kops
 
Checking Clang 11 with PVS-Studio
Checking Clang 11 with PVS-StudioChecking Clang 11 with PVS-Studio
Checking Clang 11 with PVS-StudioAndrey Karpov
 
Still Comparing "this" Pointer to Null?
Still Comparing "this" Pointer to Null?Still Comparing "this" Pointer to Null?
Still Comparing "this" Pointer to Null?Andrey Karpov
 
Dot Net Accenture
Dot Net AccentureDot Net Accenture
Dot Net AccentureSri K
 
Inversion of Control and Dependency Injection
Inversion of Control and Dependency InjectionInversion of Control and Dependency Injection
Inversion of Control and Dependency InjectionDinesh Sharma
 
Analyzing ReactOS One More Time
Analyzing ReactOS One More TimeAnalyzing ReactOS One More Time
Analyzing ReactOS One More TimePVS-Studio
 

La actualidad más candente (20)

What is SObjectizer 5.5
What is SObjectizer 5.5What is SObjectizer 5.5
What is SObjectizer 5.5
 
arataga. SObjectizer and RESTinio in action: a real-world example
arataga. SObjectizer and RESTinio in action: a real-world examplearataga. SObjectizer and RESTinio in action: a real-world example
arataga. SObjectizer and RESTinio in action: a real-world example
 
Bot builder v4 HOL
Bot builder v4 HOLBot builder v4 HOL
Bot builder v4 HOL
 
Date Processing Attracts Bugs or 77 Defects in Qt 6
Date Processing Attracts Bugs or 77 Defects in Qt 6Date Processing Attracts Bugs or 77 Defects in Qt 6
Date Processing Attracts Bugs or 77 Defects in Qt 6
 
2. Design patterns. part #2
2. Design patterns. part #22. Design patterns. part #2
2. Design patterns. part #2
 
What's New In Python 2.6
What's New In Python 2.6What's New In Python 2.6
What's New In Python 2.6
 
PVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd CheckPVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd Check
 
Testing RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkTesting RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured framework
 
The Little Unicorn That Could
The Little Unicorn That CouldThe Little Unicorn That Could
The Little Unicorn That Could
 
Creating a Java EE 7 Websocket Chat Application
Creating a Java EE 7 Websocket Chat ApplicationCreating a Java EE 7 Websocket Chat Application
Creating a Java EE 7 Websocket Chat Application
 
ExtJs Basic Part-1
ExtJs Basic Part-1ExtJs Basic Part-1
ExtJs Basic Part-1
 
Checking Clang 11 with PVS-Studio
Checking Clang 11 with PVS-StudioChecking Clang 11 with PVS-Studio
Checking Clang 11 with PVS-Studio
 
Still Comparing "this" Pointer to Null?
Still Comparing "this" Pointer to Null?Still Comparing "this" Pointer to Null?
Still Comparing "this" Pointer to Null?
 
Easy mock
Easy mockEasy mock
Easy mock
 
Android session-5-sajib
Android session-5-sajibAndroid session-5-sajib
Android session-5-sajib
 
JavaScript Refactoring
JavaScript RefactoringJavaScript Refactoring
JavaScript Refactoring
 
Dot Net Accenture
Dot Net AccentureDot Net Accenture
Dot Net Accenture
 
Inversion of Control and Dependency Injection
Inversion of Control and Dependency InjectionInversion of Control and Dependency Injection
Inversion of Control and Dependency Injection
 
TY.BSc.IT Java QB U1
TY.BSc.IT Java QB U1TY.BSc.IT Java QB U1
TY.BSc.IT Java QB U1
 
Analyzing ReactOS One More Time
Analyzing ReactOS One More TimeAnalyzing ReactOS One More Time
Analyzing ReactOS One More Time
 

Similar a Dive into SObjectizer 5.5. Third part. Coops

What’s new in SObjectizer 5.5.8
What’s new in SObjectizer 5.5.8What’s new in SObjectizer 5.5.8
What’s new in SObjectizer 5.5.8Yauheni Akhotnikau
 
What is SObjectizer 5.7 (at v.5.7.0)
What is SObjectizer 5.7 (at v.5.7.0)What is SObjectizer 5.7 (at v.5.7.0)
What is SObjectizer 5.7 (at v.5.7.0)Yauheni Akhotnikau
 
What is SObjectizer 5.6 (at v.5.6.0)
What is SObjectizer 5.6 (at v.5.6.0)What is SObjectizer 5.6 (at v.5.6.0)
What is SObjectizer 5.6 (at v.5.6.0)Yauheni Akhotnikau
 
Cis 407 i lab 6 of 7
Cis 407 i lab 6 of 7Cis 407 i lab 6 of 7
Cis 407 i lab 6 of 7helpido9
 
Connecting your Python App to OpenERP through OOOP
Connecting your Python App to OpenERP through OOOPConnecting your Python App to OpenERP through OOOP
Connecting your Python App to OpenERP through OOOPraimonesteve
 
Drupal Module Development
Drupal Module DevelopmentDrupal Module Development
Drupal Module DevelopmentSumeet Pareek
 
Advanced Module development
Advanced Module developmentAdvanced Module development
Advanced Module developmentdrupalindia
 
Getting started-with-oracle-so a-viii
Getting started-with-oracle-so a-viiiGetting started-with-oracle-so a-viii
Getting started-with-oracle-so a-viiiAmit Sharma
 
Cis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry universityCis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry universitylhkslkdh89009
 
Testing ASP.net Web Applications using Ruby
Testing ASP.net Web Applications using RubyTesting ASP.net Web Applications using Ruby
Testing ASP.net Web Applications using RubyBen Hall
 
Why should we use an INTERFACE even when we only have one concrete class?
Why should we use an INTERFACE even when we only have one concrete class?Why should we use an INTERFACE even when we only have one concrete class?
Why should we use an INTERFACE even when we only have one concrete class?Rafal Ksiazek
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)vikram singh
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2vikram singh
 
MongoDB - How to model and extract your data
MongoDB - How to model and extract your dataMongoDB - How to model and extract your data
MongoDB - How to model and extract your dataFrancesco Lo Franco
 
need help completing week 6 ilab.. i will upload what I currently ha.docx
need help completing week 6 ilab.. i will upload what I currently ha.docxneed help completing week 6 ilab.. i will upload what I currently ha.docx
need help completing week 6 ilab.. i will upload what I currently ha.docxniraj57
 
Cis407 a ilab 5 web application development devry university
Cis407 a ilab 5 web application development devry universityCis407 a ilab 5 web application development devry university
Cis407 a ilab 5 web application development devry universitylhkslkdh89009
 
Promises, promises, and then observables
Promises, promises, and then observablesPromises, promises, and then observables
Promises, promises, and then observablesStefan Charsley
 
How to use Salesforce composite request connector in Mule
How to use Salesforce composite request connector in MuleHow to use Salesforce composite request connector in Mule
How to use Salesforce composite request connector in MuleAlexandra N. Martinez
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)vikram singh
 

Similar a Dive into SObjectizer 5.5. Third part. Coops (20)

What’s new in SObjectizer 5.5.8
What’s new in SObjectizer 5.5.8What’s new in SObjectizer 5.5.8
What’s new in SObjectizer 5.5.8
 
What is SObjectizer 5.7 (at v.5.7.0)
What is SObjectizer 5.7 (at v.5.7.0)What is SObjectizer 5.7 (at v.5.7.0)
What is SObjectizer 5.7 (at v.5.7.0)
 
What is SObjectizer 5.6 (at v.5.6.0)
What is SObjectizer 5.6 (at v.5.6.0)What is SObjectizer 5.6 (at v.5.6.0)
What is SObjectizer 5.6 (at v.5.6.0)
 
Cis 407 i lab 6 of 7
Cis 407 i lab 6 of 7Cis 407 i lab 6 of 7
Cis 407 i lab 6 of 7
 
Connecting your Python App to OpenERP through OOOP
Connecting your Python App to OpenERP through OOOPConnecting your Python App to OpenERP through OOOP
Connecting your Python App to OpenERP through OOOP
 
Soa8
Soa8Soa8
Soa8
 
Drupal Module Development
Drupal Module DevelopmentDrupal Module Development
Drupal Module Development
 
Advanced Module development
Advanced Module developmentAdvanced Module development
Advanced Module development
 
Getting started-with-oracle-so a-viii
Getting started-with-oracle-so a-viiiGetting started-with-oracle-so a-viii
Getting started-with-oracle-so a-viii
 
Cis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry universityCis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry university
 
Testing ASP.net Web Applications using Ruby
Testing ASP.net Web Applications using RubyTesting ASP.net Web Applications using Ruby
Testing ASP.net Web Applications using Ruby
 
Why should we use an INTERFACE even when we only have one concrete class?
Why should we use an INTERFACE even when we only have one concrete class?Why should we use an INTERFACE even when we only have one concrete class?
Why should we use an INTERFACE even when we only have one concrete class?
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2
 
MongoDB - How to model and extract your data
MongoDB - How to model and extract your dataMongoDB - How to model and extract your data
MongoDB - How to model and extract your data
 
need help completing week 6 ilab.. i will upload what I currently ha.docx
need help completing week 6 ilab.. i will upload what I currently ha.docxneed help completing week 6 ilab.. i will upload what I currently ha.docx
need help completing week 6 ilab.. i will upload what I currently ha.docx
 
Cis407 a ilab 5 web application development devry university
Cis407 a ilab 5 web application development devry universityCis407 a ilab 5 web application development devry university
Cis407 a ilab 5 web application development devry university
 
Promises, promises, and then observables
Promises, promises, and then observablesPromises, promises, and then observables
Promises, promises, and then observables
 
How to use Salesforce composite request connector in Mule
How to use Salesforce composite request connector in MuleHow to use Salesforce composite request connector in Mule
How to use Salesforce composite request connector in Mule
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)
 

Más de Yauheni Akhotnikau

Actor Model and C++: what, why and how? (March 2020 Edition)
Actor Model and C++: what, why and how? (March 2020 Edition)Actor Model and C++: what, why and how? (March 2020 Edition)
Actor Model and C++: what, why and how? (March 2020 Edition)Yauheni Akhotnikau
 
[C++ CoreHard Autumn 2018] Actors vs CSP vs Task...
[C++ CoreHard Autumn 2018] Actors vs CSP vs Task...[C++ CoreHard Autumn 2018] Actors vs CSP vs Task...
[C++ CoreHard Autumn 2018] Actors vs CSP vs Task...Yauheni Akhotnikau
 
Shrimp: A Rather Practical Example Of Application Development With RESTinio a...
Shrimp: A Rather Practical Example Of Application Development With RESTinio a...Shrimp: A Rather Practical Example Of Application Development With RESTinio a...
Shrimp: A Rather Practical Example Of Application Development With RESTinio a...Yauheni Akhotnikau
 
Акторы в C++: взгляд старого практикующего актородела (St. Petersburg C++ Use...
Акторы в C++: взгляд старого практикующего актородела (St. Petersburg C++ Use...Акторы в C++: взгляд старого практикующего актородела (St. Petersburg C++ Use...
Акторы в C++: взгляд старого практикующего актородела (St. Petersburg C++ Use...Yauheni Akhotnikau
 
Акторы на C++: стоило ли оно того?
Акторы на C++: стоило ли оно того?Акторы на C++: стоило ли оно того?
Акторы на C++: стоило ли оно того?Yauheni Akhotnikau
 
25 Years of C++ History Flashed in Front of My Eyes
25 Years of C++ History Flashed in Front of My Eyes25 Years of C++ History Flashed in Front of My Eyes
25 Years of C++ History Flashed in Front of My EyesYauheni Akhotnikau
 
GECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon 2017: C++ - a Monster that no one likes but that will outlast them allGECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon 2017: C++ - a Monster that no one likes but that will outlast them allYauheni Akhotnikau
 
Actor Model and C++: what, why and how?
Actor Model and C++: what, why and how?Actor Model and C++: what, why and how?
Actor Model and C++: what, why and how?Yauheni Akhotnikau
 
Шишки, набитые за 15 лет использования акторов в C++
Шишки, набитые за 15 лет использования акторов в C++Шишки, набитые за 15 лет использования акторов в C++
Шишки, набитые за 15 лет использования акторов в C++Yauheni Akhotnikau
 
Для чего мы делали свой акторный фреймворк и что из этого вышло?
Для чего мы делали свой акторный фреймворк и что из этого вышло?Для чего мы делали свой акторный фреймворк и что из этого вышло?
Для чего мы делали свой акторный фреймворк и что из этого вышло?Yauheni Akhotnikau
 
Модель акторов и C++ что, зачем и как?
Модель акторов и C++ что, зачем и как?Модель акторов и C++ что, зачем и как?
Модель акторов и C++ что, зачем и как?Yauheni Akhotnikau
 
What's new in SObjectizer 5.5.9
What's new in SObjectizer 5.5.9What's new in SObjectizer 5.5.9
What's new in SObjectizer 5.5.9Yauheni Akhotnikau
 
Погружение в SObjectizer 5.5. Вводная часть
Погружение в SObjectizer 5.5. Вводная частьПогружение в SObjectizer 5.5. Вводная часть
Погружение в SObjectizer 5.5. Вводная частьYauheni Akhotnikau
 

Más de Yauheni Akhotnikau (14)

Actor Model and C++: what, why and how? (March 2020 Edition)
Actor Model and C++: what, why and how? (March 2020 Edition)Actor Model and C++: what, why and how? (March 2020 Edition)
Actor Model and C++: what, why and how? (March 2020 Edition)
 
[C++ CoreHard Autumn 2018] Actors vs CSP vs Task...
[C++ CoreHard Autumn 2018] Actors vs CSP vs Task...[C++ CoreHard Autumn 2018] Actors vs CSP vs Task...
[C++ CoreHard Autumn 2018] Actors vs CSP vs Task...
 
Shrimp: A Rather Practical Example Of Application Development With RESTinio a...
Shrimp: A Rather Practical Example Of Application Development With RESTinio a...Shrimp: A Rather Practical Example Of Application Development With RESTinio a...
Shrimp: A Rather Practical Example Of Application Development With RESTinio a...
 
Акторы в C++: взгляд старого практикующего актородела (St. Petersburg C++ Use...
Акторы в C++: взгляд старого практикующего актородела (St. Petersburg C++ Use...Акторы в C++: взгляд старого практикующего актородела (St. Petersburg C++ Use...
Акторы в C++: взгляд старого практикующего актородела (St. Petersburg C++ Use...
 
Акторы на C++: стоило ли оно того?
Акторы на C++: стоило ли оно того?Акторы на C++: стоило ли оно того?
Акторы на C++: стоило ли оно того?
 
25 Years of C++ History Flashed in Front of My Eyes
25 Years of C++ History Flashed in Front of My Eyes25 Years of C++ History Flashed in Front of My Eyes
25 Years of C++ History Flashed in Front of My Eyes
 
GECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon 2017: C++ - a Monster that no one likes but that will outlast them allGECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon 2017: C++ - a Monster that no one likes but that will outlast them all
 
Actor Model and C++: what, why and how?
Actor Model and C++: what, why and how?Actor Model and C++: what, why and how?
Actor Model and C++: what, why and how?
 
Шишки, набитые за 15 лет использования акторов в C++
Шишки, набитые за 15 лет использования акторов в C++Шишки, набитые за 15 лет использования акторов в C++
Шишки, набитые за 15 лет использования акторов в C++
 
Для чего мы делали свой акторный фреймворк и что из этого вышло?
Для чего мы делали свой акторный фреймворк и что из этого вышло?Для чего мы делали свой акторный фреймворк и что из этого вышло?
Для чего мы делали свой акторный фреймворк и что из этого вышло?
 
Модель акторов и C++ что, зачем и как?
Модель акторов и C++ что, зачем и как?Модель акторов и C++ что, зачем и как?
Модель акторов и C++ что, зачем и как?
 
What's new in SObjectizer 5.5.9
What's new in SObjectizer 5.5.9What's new in SObjectizer 5.5.9
What's new in SObjectizer 5.5.9
 
Погружение в SObjectizer 5.5. Вводная часть
Погружение в SObjectizer 5.5. Вводная частьПогружение в SObjectizer 5.5. Вводная часть
Погружение в SObjectizer 5.5. Вводная часть
 
Обзор SObjectizer 5.5
Обзор SObjectizer 5.5Обзор SObjectizer 5.5
Обзор SObjectizer 5.5
 

Último

What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 

Último (20)

What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 

Dive into SObjectizer 5.5. Third part. Coops

  • 1. Dive into SObjectizer-5.5 SObjectizer Team, Jan 2016 Third Part: More About Coops (at v.5.5.15)
  • 2. This is the next part of the serie of presentations with deep introduction into features of SObjectizer-5.5. This part is dedicated to such important feature as cooperations. In particular: ● parent-child relationship; ● resource lifetime management; ● reg/dereg notificators. SObjectizer Team, Jan 2016
  • 4. Cooperation (or coop in short) is a way for binding several tightly related agents into a whole entity. Coop is registered in SObjectizer Environment in a transactional manner: all agents from the cooperation must be registered successfully or no one of them. When a coop is being deregistered all its agents are deregistered and destroyed at the same time. SObjectizer Team, Jan 2016
  • 5. There could be agents which require creation of additional coop(s) for performing their work. Let's imagine an agent which is responsible of receiving and processing of some requests. Payment requests, for example. SObjectizer Team, Jan 2016
  • 6. Processing of each payment request requires several operations: ● checking payments parameters, ● checking the operation risks, ● checking the availability of funds ● and so on... The request receiver could do those actions for every payment by itself. But this will lead to very complicated logic of request receiver. SObjectizer Team, Jan 2016
  • 7. There is much simpler approach: delegation of processing of one request to a separate processor agent. In that case the request receiver will only receive new requests and create new coops with actual request processors for each new request. Receiver and processor agents will have more simple logic and it is good. But there will be a new question... SObjectizer Team, Jan 2016
  • 8. Who and how will control lifetime of all cooperations with request processors? SObjectizer Team, Jan 2016
  • 9. Very simple view of that problem: Someone could call deregister_coop() for request receiver’s coop. As result all coops with request processors must be deregistered too. But how it could be done? SObjectizer Team, Jan 2016
  • 10. Such feature as child coop is coming into play here. SObjectizer Team, Jan 2016
  • 11. SObjectizer-5 allows to mark new coop as a child of any existing coop. In this case SObjectizer guarantees that all children coops will be deregistered and destroyed before its parent coop. SObjectizer Team, Jan 2016
  • 12. It means that if we have, for example, a parent coop with name “manager” and a child coop with name “request_receiver” and do call: env.deregister_coop( "manager", so_5::dereg_reason::normal ); Then SObjectizer-5 will deregister and destroy “request_receiver” and only then “manager” coop will be deregistered and destroyed. SObjectizer Team, Jan 2016
  • 13. Child coop could have its own child coops too. It means that “request_receiver” coop could have any number of child coops like “request_processor_1”, “request_processor_2” and so on. All of them will be automatically destroyed when top-level parent coop “manager” is deregistered. SObjectizer Team, Jan 2016
  • 14. Parent-child relationship between coops allows to build coops hierarchies: a top-level coop creates child coops, those create its own child coops and so on. If a top-level coop is being deregistered by some reason then all its child coops (and children of children and so on) will be deregistered too. A programmer could no takes care about this. SObjectizer Team, Jan 2016
  • 15. There are several ways to make a child coop... SObjectizer Team, Jan 2016
  • 16. The first way, the oldest and verbose: auto coop = env.create_coop( "request_processor_1" ); coop->set_parent_coop_name( "request_receiver" ); ... // Filling the coop. env.register_coop( std::move( coop ) ); Coop “request_processor_1” will be a child for coop “request_receiver”. SObjectizer Team, Jan 2016
  • 17. The second one applicable if there is an agent from the parent coop: void parent_agent::make_new_coop() { auto coop = so_5::create_child_coop( *this, "request_processor_1" ); ... // Filling the coop. so_environment().register_coop( std::move( coop ) ); } Name of the parent coop will be set automatically. SObjectizer Team, Jan 2016
  • 18. The third one is available since v.5.5.5: void parent_agent::make_new_coop() { so_5::introduce_child_coop( *this, "request_processor_1", []( so_5::coop_t & coop ) { ... // Filling the coop. } ); } Name of the parent coop will be set automatically. SObjectizer Team, Jan 2016
  • 20. Sometimes it is necessary to manage lifetime of some resources. For example all agents from your coop should have a reference to the same DB connection object. If this connection object is allocated dynamically you can pass a shared_ptr to every agent's constructor. Something like: SObjectizer Team, Jan 2016
  • 21. class first_agent : public so_5::agent_t { ... public : first_agent( context_t ctx, std::shared_ptr< db_connection > conn, ... ); ... private : std::shared_ptr< db_connection > connection_; }; class second_agent : public so_5::agent_t { ... public : second_agent( context_t ctx, std::shared_ptr< db_connection > conn, ... ); ... private : std::shared_ptr< db_connection > connection_; }; env.introduce_coop( []( so_5::coop_t & coop ) { std::shared_ptr< db_connection > connection = connect_to_db(...); coop.make_agent< first_agent >( connection, ... ); coop.make_agent< second_agent >( connection, ... ); ... } ); SObjectizer Team, Jan 2016
  • 22. In such case you make tight coupling between application domain logic of your agents and DB connection lifetime management. SObjectizer Team, Jan 2016
  • 23. What if this lifetime management need to be changed in the future? What if connection object is controlled by someone else and you have a simple reference to it (not shared_ptr)? You will need to do some rewriting... SObjectizer Team, Jan 2016
  • 24. class first_agent : public so_5::agent_t { ... public : first_agent( context_t ctx, db_connection & conn, ... ); // The constructor has to be changed. ... private : db_connection & connection_; // Declaration of the member has to be changed. }; class second_agent : public so_5::agent_t { ... public : second_agent( context_t ctx, db_connection & conn, ... ); // The constructor has to be changed. ... private : db_connection & connection_; // Declaration of the member has to be changed. }; ... db_connection & conn = receive_connection_from_somewhere(); env.introduce_coop( [&conn]( so_5::coop_t & coop ) { coop.make_agent< first_agent >( conn, ... ); coop.make_agent< second_agent >( conn, ... ); ... } ); SObjectizer Team, Jan 2016
  • 25. SObjectizer-5 has a tool for decoupling resource lifetime management from agent's domain-specific logic. This is coop_t::take_under_control(). Method coop_t::take_under_control() allows to pass dynamically allocated object under the control of the cooperation. The object placed under control will be deallocated only after destroying all agents of the coop. SObjectizer Team, Jan 2016
  • 26. The behaviour of take_under_control() allows to use the reference to controlled object even from agent's destructor... SObjectizer Team, Jan 2016
  • 27. class request_processor : public so_5::agent_t { public : request_processor( context_t ctx, db_connection & connection ); ~request_processor() { if( !commited() ) // Assume that this reference is still valid. connection_.commit(); } ... private : db_connection & connection_; }; ... env.introduce_coop( []( so_5::coop_t & coop ) { // Place DB connection under the control of the cooperation. auto & connection = *coop.take_under_control(create_connection(...)); // Reference to DB connection will be valid even in requests_processor's destructor. coop->make_agent< request_processor >( connection ); ... } ); SObjectizer Team, Jan 2016
  • 28. Parent-child relationship could also be used for resource lifetime management... SObjectizer Team, Jan 2016
  • 29. class request_receiver : public so_5::agent_t { std::unique_ptr< db_connection > connection_; ... public : virtual void so_evt_start() override { connection_ = make_db_connection(...); ... } ... private : void evt_new_request( const request & evt ) { // New request handler must be created. so_5::introduce_child_coop( *this, [=]( so_5::coop_t & coop ) { // Reference to DB connection will be valid even in requests_processor's destructor. // It is because agents from child cooperation will be destroyed before any of // agents from the parent cooperation. coop->make_agent< request_processor >( connection ); ... } ); } }; SObjectizer Team, Jan 2016
  • 31. It is not easy to detect precise moments when a coop is completely registered or completely deregistered. The biggest problem is a detection of complete coop deregistration. It is because calling to environment_t::deregister_coop() just initiates coop deregistration process. But the entire process of deregistration could take a long time. SObjectizer Team, Jan 2016
  • 32. To simplify that there are such things as registration and deregistration notificators. Notificator could be bound to a coop and it will be called when coop registration/deregistration process is finished. SObjectizer Team, Jan 2016
  • 33. The simplest reg/dereg notificators: env.introduce_coop( []( so_5::coop_t & coop ) { coop.add_reg_notificator( []( so_5::environment_t &, const std::string & name ) { std::cout << "registered: " << name << std::endl; } ); coop.add_dereg_notificator( []( so_5::environment_t &, const std::string & name, const so_5::coop_dereg_reason_t & ) { std::cout << "deregistered: " << name << std::endl; } ); ... } ); Name of coop will be printed to stdout on coop registration and deregistration. SObjectizer Team, Jan 2016
  • 34. Usually reg/dereg notifications are used for sending messages to some mboxes. Because this scenario is widely used there are two ready-to- use notificators in SObjectizer-5.5. They are created by make_coop_reg_notificator() and make_coop_dereg_notificator() functions... SObjectizer Team, Jan 2016
  • 35. The standard notificators: auto notify_mbox = env.create_local_mbox(); env.introduce_coop( [&]( so_5::coop_t & coop ) { // An instance of so_5::msg_coop_registered will be sent to notify_mbox // when the cooperation is registered. coop.add_reg_notificator( so_5::make_coop_reg_notificator( notify_mbox ) ); // An instance of so_5::msg_coop_deregistered will be sent to // notify_mbox when the cooperation is deregistered. coop.add_dereg_notificator( so_5::make_coop_dereg_notificator( notify_mbox ) ); ... } ); SObjectizer Team, Jan 2016
  • 36. Coop dereg notificators can be used for implementation of Erlang-like supervisors. For example, request receiver could receive notification about deregistration of child coops and restart them if they fail... SObjectizer Team, Jan 2016
  • 37. Very simple way of controlling a child (1/2): class request_receiver : public so_5::agent_t { public : virtual void so_define_agent() override { // msg_coop_deregistered must be handled. so_subscribe_self().event( &request_receiver::evt_child_finished ); ... } ... private : void evt_new_request( const request & req ) { auto child_name = store_request_info( req ); so_5::introduce_child_coop( child_name, [&]( so_5::coop_t & coop ) { ... // Filling the coop with agents. // Dereg notificator is necessary to receive info about child disappearance. SObjectizer Team, Jan 2016
  • 38. Very simple way of controlling a child (2/2): // Standard notificator will be used. coop.add_dereg_notificator( // We want a message to request_receiver direct_mbox. so_5::make_coop_dereg_notificator( so_direct_mbox() ) ); } ); ... } void evt_child_finished( const so_5::msg_coop_deregistered & evt ) { // If child cooperation failed its dereg reason will differ // from the normal value. if( so_5::dereg_reason::normal != evt.m_reason.reason() ) recreate_child_coop( evt.m_coop_name ); else remove_request_info( evt.m_coop_name ); } ... }; SObjectizer Team, Jan 2016
  • 39. That is almost all what it needs to be known about agent coops. There are yet more issues like coop deregistration reasons and exception reaction inheritance… But those topics will be covered in the next parts of “Dive into SObjectizer-5.5” SObjectizer Team, Jan 2016
  • 40. Additional Information: Project’s home: http://sourceforge.net/projects/sobjectizer Documentation: http://sourceforge.net/p/sobjectizer/wiki/ Forum: http://sourceforge.net/p/sobjectizer/discussion/ Google-group: https://groups.google.com/forum/#!forum/sobjectizer GitHub mirror: https://github.com/masterspline/SObjectizer