SObjectizer 5.8
|
SObjectizer Environment. More...
#include <environment.hpp>
Classes | |
struct | internals_t |
Internal details of SObjectizer Environment object. More... | |
Public Member Functions | |
environment_t (environment_params_t &&so_environment_params) | |
virtual | ~environment_t () |
environment_t (const environment_t &)=delete | |
environment_t & | operator= (const environment_t &)=delete |
void | call_exception_logger (const std::exception &event_exception, const coop_handle_t &coop) noexcept |
Call event exception logger for logging an exception. | |
exception_reaction_t | exception_reaction () const noexcept |
An exception reaction for the whole SO Environment. | |
error_logger_t & | error_logger () const |
Get the error_logger object. | |
template<class Agent , typename... Args> | |
std::unique_ptr< Agent > | make_agent (Args &&... args) |
Helper method for simplification of agents creation. | |
stats::controller_t & | stats_controller () |
Access to controller of run-time monitoring. | |
stats::repository_t & | stats_repository () |
Access to repository of data sources for run-time monitoring. | |
so_5::disp::abstract_work_thread_factory_shptr_t | work_thread_factory () const noexcept |
Access to the global work thread factory. | |
template<typename... Args> | |
decltype(auto) | introduce_coop (Args &&... args) |
Helper method for simplification of cooperation creation and registration. | |
work_thread_activity_tracking_t | work_thread_activity_tracking () const |
Get activity tracking flag for the whole SObjectizer Environment. | |
disp_binder_shptr_t | so_make_default_disp_binder () |
Get binding to the default dispatcher. | |
bool | autoshutdown_disabled () const |
Get autoshutdown_disabled flag. | |
so_5::timer_id_t | so_schedule_timer (const low_level_api::schedule_timer_params_t params) |
Schedule timer event. | |
void | so_single_timer (const low_level_api::single_timer_params_t params) |
Schedule a single shot timer event. | |
template<typename Lambda > | |
mbox_t | make_custom_mbox (Lambda &&lambda) |
Create a custom mbox. | |
Methods for working with mboxes. | |
mbox_t | create_mbox () |
Create an anonymous MPMC mbox. | |
mbox_t | create_mbox (nonempty_name_t mbox_name) |
Create named MPMC mbox. | |
mbox_t | introduce_named_mbox (mbox_namespace_name_t mbox_namespace, nonempty_name_t mbox_name, const std::function< mbox_t() > &mbox_factory) |
Introduce named mbox with user-provided factory. | |
Method for working with message chains. | |
mchain_t | create_mchain (const mchain_params_t ¶ms) |
Create message chain. | |
Method for working with dispatchers. | |
void | install_exception_logger (event_exception_logger_unique_ptr_t logger) |
Set up an exception logger. | |
Methods for working with cooperations. | |
coop_unique_holder_t | make_coop () |
Create a cooperation. | |
coop_unique_holder_t | make_coop (disp_binder_shptr_t disp_binder) |
Create a cooperation with specified dispatcher binder. | |
coop_unique_holder_t | make_coop (coop_handle_t parent) |
Create a new cooperation that will be a child for specified parent coop. | |
coop_unique_holder_t | make_coop (coop_handle_t parent, disp_binder_shptr_t disp_binder) |
Create a new cooperation that will be a child for specified parent coop. | |
coop_handle_t | register_coop (coop_unique_holder_t agent_coop) |
Register a cooperation. | |
template<class A > | |
coop_handle_t | register_agent_as_coop (std::unique_ptr< A > agent) |
Register single agent as a cooperation. | |
template<class A > | |
coop_handle_t | register_agent_as_coop (std::unique_ptr< A > agent, disp_binder_shptr_t disp_binder) |
Register single agent as a cooperation with specified dispatcher binder. | |
void | deregister_coop (coop_handle_t coop, int reason) noexcept |
Deregister the cooperation. | |
Methods for working with layers. | |
template<class SO_Layer > | |
SO_Layer * | query_layer_noexcept () const |
template<class SO_Layer > | |
SO_Layer * | query_layer () const |
Get access to the layer with exception if layer is not found. | |
template<class SO_Layer > | |
void | add_extra_layer (std::unique_ptr< SO_Layer > layer_ptr) |
Add an additional layer. | |
Methods for starting, initializing and stopping of the Run-Time. | |
void | run () |
Run the SObjectizer Run-Time. | |
virtual void | init ()=0 |
Initialization hook. | |
void | stop () noexcept |
Send a shutdown signal to the Run-Time. | |
Methods for working with stop_guards. | |
stop_guard_t::setup_result_t | setup_stop_guard (stop_guard_shptr_t guard, stop_guard_t::what_if_stop_in_progress_t reaction_on_stop_in_progress=stop_guard_t::what_if_stop_in_progress_t::throw_exception) |
Set up a new stop_guard. | |
void | remove_stop_guard (stop_guard_shptr_t guard) |
Remove stop_guard and complete the stop operation if necessary. | |
Methods for working with msg_tracing's filters. | |
void | change_message_delivery_tracer_filter (so_5::msg_tracing::filter_shptr_t filter) |
Change the current msg_tracing's filter to a new one. | |
Private Member Functions | |
environment_t & | self_ref () |
Auxiliary methods for getting reference to itself. | |
layer_t * | query_layer (const std::type_index &type) const |
Access to an additional layer. | |
void | add_extra_layer (const std::type_index &type, const layer_ref_t &layer) |
Add an additional layer. | |
void | remove_extra_layer (const std::type_index &type) |
Remove an additional layer. | |
mbox_t | do_make_custom_mbox (custom_mbox_details::creator_iface_t &creator) |
Actual creation of a custom mbox. | |
Implementation details related to run/stop functionality. | |
void | imp_run_stats_controller_and_go_further () |
Run controller for run-time monitoring and call next run stage. | |
void | imp_run_layers_and_go_further () |
Run layers and call next run stage. | |
void | imp_run_infrastructure () |
Launch environment infrastructure and wait for finish. | |
Private Attributes | |
std::unique_ptr< internals_t > | m_impl |
SObjectizer Environment internals. | |
Friends | |
class | so_5::impl::internal_env_iface_t |
SObjectizer Environment.
The SObjectizer Environment provides a basic infrastructure for the SObjectizer Run-Time execution.
The main method of starting SObjectizer Environment creates a class derived from the environment_t and reimplementing the environment_t::init() method. This method should be used to define starting actions of application. For example first application cooperations can be registered here and starting messages can be sent to them.
The SObjectizer Environment calls the environment_t::init() when the SObjectizer Run-Time is successfully started. If something happened during the Run-Time startup then the method init() will not be called.
The SObjectizer Run-Time is started by the environment_t::run(). This method blocks the caller thread until SObjectizer completely finished its work.
The SObjectizer Run-Time is finished by the environment_t::stop(). This method doesn't block the caller thread. Instead it sends a special shutdown signal to the Run-Time. The SObjectizer Run-Time then informs agents about this and waits finish of agents work. The SObjectizer Run-Time finishes if all agents are stopped and all cooperations are deregistered.
Methods of the SObjectizer Environment can be splitted into the following groups:
SObjectizer Environment allows creation of named and anonymous mboxes. Syncronization objects for these mboxes can be obtained from common pools or assigned by a user during mbox creation.
Mboxes are created by environment_t::create_mbox() methods. All these methods return the mbox_t which is a smart reference to the mbox.
An anonymous mbox is automatically destroyed when the last reference to it is destroyed. So, to save the anonymous mbox, the mbox_ref from the create_mbox() should be stored somewhere.
Cooperations can be created by environment_t::make_coop() methods.
The method environment_t::register_coop() should be used for the cooperation registration.
Method environment_t::deregister_coop() should be used for the cooperation deregistration.
Definition at line 955 of file environment.hpp.
|
explicit |
so_environment_params | Initialization params. |
Definition at line 513 of file environment.cpp.
|
virtual |
Definition at line 519 of file environment.cpp.
|
delete |
|
private |
Add an additional layer.
Definition at line 693 of file environment.cpp.
|
inline |
Add an additional layer.
Definition at line 1606 of file environment.hpp.
bool so_5::environment_t::autoshutdown_disabled | ( | ) | const |
Get autoshutdown_disabled flag.
Autoshutdown feature is on by default. It can be turned off in environment_params_t. This methods returns true if autoshutdown is turned off.
Definition at line 783 of file environment.cpp.
|
noexcept |
Call event exception logger for logging an exception.
event_exception | Exception caught. |
coop | A cooperation to which agent is belong. |
Definition at line 731 of file environment.cpp.
void so_5::environment_t::change_message_delivery_tracer_filter | ( | so_5::msg_tracing::filter_shptr_t | filter | ) |
Change the current msg_tracing's filter to a new one.
Usage example:
exception_t | if message delivery tracing is disabled. |
filter | A new filter to be used. It can be an empty pointer. In this case all trace messages will be passed to tracer object. |
Definition at line 824 of file environment.cpp.
|
nodiscard |
Create an anonymous MPMC mbox.
Usage example:
Definition at line 524 of file environment.cpp.
|
nodiscard |
Create named MPMC mbox.
If mbox_name is unique then a new mbox will be created. If not the reference to existing mbox will be returned.
Usage example:
In this example both agents will use the same mbox instance.
mbox_name | Mbox name. |
Definition at line 530 of file environment.cpp.
mchain_t so_5::environment_t::create_mchain | ( | const mchain_params_t & | params | ) |
Create message chain.
params | Parameters for a new bag. |
Definition at line 549 of file environment.cpp.
|
inlinenoexcept |
Deregister the cooperation.
Method searches the cooperation within registered cooperations and if it is found deregisters it.
Deregistration can take some time.
At first a special signal is sent to cooperation agents. By receiving these signal agents stop receiving new messages. When the local event queue for an agent becomes empty the agent informs the cooperation about this. When the cooperation receives all these signals from agents it informs the SObjectizer Run-Time.
Only after this the cooperation is deregistered on the special context.
After the cooperation deregistration agents are unbound from dispatchers.
Usage example:
coop | The coop to be deregistered. |
reason | Deregistration reason. |
Definition at line 1556 of file environment.hpp.
|
private |
error_logger_t & so_5::environment_t::error_logger | ( | ) | const |
|
noexcept |
An exception reaction for the whole SO Environment.
Definition at line 741 of file environment.cpp.
|
private |
Launch environment infrastructure and wait for finish.
Definition at line 889 of file environment.cpp.
|
private |
Run layers and call next run stage.
Definition at line 849 of file environment.cpp.
|
private |
Run controller for run-time monitoring and call next run stage.
Definition at line 837 of file environment.cpp.
|
pure virtual |
Initialization hook.
Implemented in so_5::anonymous_namespace{wrapped_env.cpp}::actual_environment_t, and so_5::impl::so_quick_environment_t< Init >.
void so_5::environment_t::install_exception_logger | ( | event_exception_logger_unique_ptr_t | logger | ) |
Set up an exception logger.
Definition at line 556 of file environment.cpp.
decltype(auto) so_5::environment_t::introduce_coop | ( | Args &&... | args | ) |
Helper method for simplification of cooperation creation and registration.
Definition at line 2191 of file environment.hpp.
|
nodiscard |
Introduce named mbox with user-provided factory.
This method allows a user to create own named mbox.
The create_mbox(nonempty_name_t) method always creates a standard MPMC mbox. This isn't always desirable. For example, a user may want to have a named unique_subscribers mbox. The introduce_named_mbox() allows to achieve this:
The introduce_named_mbox
work the following way:
introduce_named_mbox
method;introduce_named_mbox
), then the the value returned by mbox_factory is discarded and the existing named mbox is returned.It means then the mbox_factory is used if there is no a mbox with the name specified yet. If such a mbox is already exists then the already created mbox will be returned without calling mbox_factory.
Note that named mboxes created by this method live in separate namespaces and those namespaces aren't intersect with "the default" namespace used by the create_mbox(nonempty_name_t) method. It means that a user can create named mboxes with the same name in different namespaces and they will be different mboxes:
mbox_namespace | Name of mbox_namespace for a new mbox. |
mbox_name | Name for a new mbox. |
mbox_factory | Factory for new mbox. |
Definition at line 537 of file environment.cpp.
|
inline |
Helper method for simplification of agents creation.
Agent | type of agent to be created. |
Args | type of parameters list for agent constructor. |
Definition at line 1709 of file environment.hpp.
|
nodiscard |
Create a cooperation.
Usage example:
Definition at line 573 of file environment.cpp.
|
nodiscard |
Create a new cooperation that will be a child for specified parent coop.
The new cooperation will use the default dispatcher binder.
Usage example:
parent | Parent coop. |
Definition at line 592 of file environment.cpp.
|
nodiscard |
Create a new cooperation that will be a child for specified parent coop.
The new cooperation will use the specified dispatcher binder.
Usage example:
parent | Parent coop. |
disp_binder | A default binder for this cooperation. |
Definition at line 602 of file environment.cpp.
|
nodiscard |
Create a cooperation with specified dispatcher binder.
A binder disp_binder will be used for binding cooperation agents to the dispatcher. This binder will be default binder for this cooperation.
disp_binder | A default binder for this cooperation. |
Definition at line 582 of file environment.cpp.
|
inline |
Create a custom mbox.
Lambda | type of actual lambda with all creation actions. The Lambda must be lambda-function or functional objects with the following format: An information which is necessary for creation of a new mbox. Definition custom_mbox.hpp:32 |
Definition at line 1855 of file environment.hpp.
|
delete |
|
inline |
Get access to the layer with exception if layer is not found.
Definition at line 1591 of file environment.hpp.
|
private |
Access to an additional layer.
Definition at line 686 of file environment.cpp.
|
inline |
Get access to the layer without raising exception if layer is not found.
Definition at line 1579 of file environment.hpp.
|
inline |
Register single agent as a cooperation.
It is just a helper methods for convience.
Usage sample:
Definition at line 1444 of file environment.hpp.
|
inline |
Register single agent as a cooperation with specified dispatcher binder.
It is just a helper methods for convience.
Usage sample:
Definition at line 1471 of file environment.hpp.
coop_handle_t so_5::environment_t::register_coop | ( | coop_unique_holder_t | agent_coop | ) |
Register a cooperation.
The cooperation registration includes following steps:
If all these actions are successful then the cooperation is marked as registered.
Very simple case.
More complex case with storing coop_handle and using it for coop deregistration:
A typical scenario for register_coop() when an instance of coop is created by a separate function:
agent_coop | Cooperation to be registered. |
Definition at line 612 of file environment.cpp.
|
private |
Remove an additional layer.
void so_5::environment_t::remove_stop_guard | ( | stop_guard_shptr_t | guard | ) |
Remove stop_guard and complete the stop operation if necessary.
Every stop_guard which was added to the environment must be explicitely removed from the environment. It is done by this method. If there is no more stop_guard and the stop operation is in progress then the environment will complete the stop operation.
Usage examples:
guard | Stop guard to be removed. |
Definition at line 815 of file environment.cpp.
void so_5::environment_t::run | ( | ) |
Run the SObjectizer Run-Time.
Definition at line 701 of file environment.cpp.
|
private |
Auxiliary methods for getting reference to itself.
Could be used in constructors without compiler warnings.
Definition at line 507 of file environment.cpp.
stop_guard_t::setup_result_t so_5::environment_t::setup_stop_guard | ( | stop_guard_shptr_t | guard, |
stop_guard_t::what_if_stop_in_progress_t | reaction_on_stop_in_progress = stop_guard_t::what_if_stop_in_progress_t::throw_exception ) |
Set up a new stop_guard.
Usage examples:
guard | Stop guard to be set. Should not be nullptr. |
reaction_on_stop_in_progress | What to do is the stop operation is already in progress? |
Definition at line 796 of file environment.cpp.
disp_binder_shptr_t so_5::environment_t::so_make_default_disp_binder | ( | ) |
Get binding to the default dispatcher.
Definition at line 777 of file environment.cpp.
so_5::timer_id_t so_5::environment_t::so_schedule_timer | ( | const low_level_api::schedule_timer_params_t | params | ) |
Schedule timer event.
params | Parameters for new timer. |
Definition at line 619 of file environment.cpp.
void so_5::environment_t::so_single_timer | ( | const low_level_api::single_timer_params_t | params | ) |
Schedule a single shot timer event.
params | Parameters for new timer. |
Definition at line 660 of file environment.cpp.
stats::controller_t & so_5::environment_t::stats_controller | ( | ) |
Access to controller of run-time monitoring.
Definition at line 753 of file environment.cpp.
stats::repository_t & so_5::environment_t::stats_repository | ( | ) |
Access to repository of data sources for run-time monitoring.
Definition at line 759 of file environment.cpp.
|
noexcept |
Send a shutdown signal to the Run-Time.
Definition at line 722 of file environment.cpp.
work_thread_activity_tracking_t so_5::environment_t::work_thread_activity_tracking | ( | ) | const |
Get activity tracking flag for the whole SObjectizer Environment.
Definition at line 771 of file environment.cpp.
|
nodiscardnoexcept |
Access to the global work thread factory.
Definition at line 765 of file environment.cpp.
|
friend |
Definition at line 957 of file environment.hpp.
|
private |
SObjectizer Environment internals.
Definition at line 2060 of file environment.hpp.