SObjectizer
5.7
|
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. More... | |
exception_reaction_t | exception_reaction () const |
An exception reaction for the whole SO Environment. More... | |
error_logger_t & | error_logger () const |
Get the error_logger object. More... | |
template<class Agent , typename... Args> | |
std::unique_ptr< Agent > | make_agent (Args &&... args) |
Helper method for simplification of agents creation. More... | |
stats::controller_t & | stats_controller () |
Access to controller of run-time monitoring. More... | |
stats::repository_t & | stats_repository () |
Access to repository of data sources for run-time monitoring. More... | |
so_5::disp::abstract_work_thread_factory_shptr_t | work_thread_factory () const noexcept |
Access to the global work thread factory. More... | |
template<typename... Args> | |
decltype(auto) | introduce_coop (Args &&... args) |
Helper method for simplification of cooperation creation and registration. More... | |
work_thread_activity_tracking_t | work_thread_activity_tracking () const |
Get activity tracking flag for the whole SObjectizer Environment. More... | |
disp_binder_shptr_t | so_make_default_disp_binder () |
Get binding to the default dispatcher. More... | |
bool | autoshutdown_disabled () const |
Get autoshutdown_disabled flag. More... | |
so_5::timer_id_t | so_schedule_timer (const low_level_api::schedule_timer_params_t params) |
Schedule timer event. More... | |
void | so_single_timer (const low_level_api::single_timer_params_t params) |
Schedule a single shot timer event. More... | |
template<typename Lambda > | |
mbox_t | make_custom_mbox (Lambda &&lambda) |
Create a custom mbox. More... | |
Methods for working with mboxes. | |
mbox_t | create_mbox () |
Create an anonymous mbox with the default mutex. More... | |
mbox_t | create_mbox (nonempty_name_t mbox_name) |
Create named mbox. More... | |
Method for working with message chains. | |
mchain_t | create_mchain (const mchain_params_t ¶ms) |
Create message chain. More... | |
Method for working with dispatchers. | |
void | install_exception_logger (event_exception_logger_unique_ptr_t logger) |
Set up an exception logger. More... | |
Methods for working with cooperations. | |
coop_unique_holder_t | make_coop () |
Create a cooperation. More... | |
coop_unique_holder_t | make_coop (disp_binder_shptr_t disp_binder) |
Create a cooperation with specified dispatcher binder. More... | |
coop_unique_holder_t | make_coop (coop_handle_t parent) |
Create a new cooperation that will be a child for specified parent coop. More... | |
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. More... | |
coop_handle_t | register_coop (coop_unique_holder_t agent_coop) |
Register a cooperation. More... | |
template<class A > | |
coop_handle_t | register_agent_as_coop (std::unique_ptr< A > agent) |
Register single agent as a cooperation. More... | |
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. More... | |
void | deregister_coop (coop_handle_t coop, int reason) noexcept |
Deregister the cooperation. More... | |
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. More... | |
template<class SO_Layer > | |
void | add_extra_layer (std::unique_ptr< SO_Layer > layer_ptr) |
Add an additional layer. More... | |
Methods for starting, initializing and stopping of the Run-Time. | |
void | run () |
Run the SObjectizer Run-Time. More... | |
virtual void | init ()=0 |
Initialization hook. More... | |
void | stop () |
Send a shutdown signal to the Run-Time. More... | |
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. More... | |
void | remove_stop_guard (stop_guard_shptr_t guard) |
Remove stop_guard and complete the stop operation if necessary. More... | |
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. More... | |
Private Member Functions | |
environment_t & | self_ref () |
Auxiliary methods for getting reference to itself. More... | |
layer_t * | query_layer (const std::type_index &type) const |
Access to an additional layer. More... | |
void | add_extra_layer (const std::type_index &type, const layer_ref_t &layer) |
Add an additional layer. More... | |
void | remove_extra_layer (const std::type_index &type) |
Remove an additional layer. More... | |
mbox_t | do_make_custom_mbox (custom_mbox_details::creator_iface_t &creator) |
Actual creation of a custom mbox. More... | |
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. More... | |
void | imp_run_layers_and_go_further () |
Run layers and call next run stage. More... | |
void | imp_run_infrastructure () |
Launch environment infrastructure and wait for finish. More... | |
Private Attributes | |
std::unique_ptr< internals_t > | m_impl |
SObjectizer Environment internals. More... | |
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.
|
explicit |
so_environment_params | Initialization params. |
|
virtual |
|
delete |
|
inline |
Add an additional layer.
|
private |
Add an additional layer.
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.
|
noexcept |
Call event exception logger for logging an exception.
event_exception | Exception caught. |
coop | A cooperation to which agent is belong. |
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. |
mbox_t so_5::environment_t::create_mbox | ( | ) |
Create an anonymous mbox with the default mutex.
mbox_t so_5::environment_t::create_mbox | ( | nonempty_name_t | mbox_name | ) |
Create named mbox.
If mbox_name is unique then a new mbox will be created. If not the reference to existing mbox will be returned.
mbox_name | Mbox name. |
mchain_t so_5::environment_t::create_mchain | ( | const mchain_params_t & | params | ) |
Create message chain.
params | Parameters for a new bag. |
|
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.
coop | The coop to be deregistered. |
reason | Deregistration reason. |
|
private |
Actual creation of a custom mbox.
error_logger_t & so_5::environment_t::error_logger | ( | ) | const |
Get the error_logger object.
exception_reaction_t so_5::environment_t::exception_reaction | ( | ) | const |
An exception reaction for the whole SO Environment.
|
private |
Launch environment infrastructure and wait for finish.
|
private |
Run layers and call next run stage.
|
private |
Run controller for run-time monitoring and call next run stage.
|
pure virtual |
Initialization hook.
Implemented in so_5::impl::so_quick_environment_t< Init >, and so_5::anonymous_namespace{wrapped_env.cpp}::actual_environment_t.
void so_5::environment_t::install_exception_logger | ( | event_exception_logger_unique_ptr_t | logger | ) |
Set up an exception logger.
decltype(auto) so_5::environment_t::introduce_coop | ( | Args &&... | args | ) |
Helper method for simplification of cooperation creation and registration.
|
inline |
Helper method for simplification of agents creation.
Agent | type of agent to be created. |
Args | type of parameters list for agent constructor. |
coop_unique_holder_t so_5::environment_t::make_coop | ( | ) |
Create a cooperation.
coop_unique_holder_t so_5::environment_t::make_coop | ( | disp_binder_shptr_t | disp_binder | ) |
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. |
coop_unique_holder_t so_5::environment_t::make_coop | ( | coop_handle_t | parent | ) |
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. |
coop_unique_holder_t so_5::environment_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.
The new cooperation will use the specified dispatcher binder.
Usage example:
parent | Parent coop. |
disp_binder | A default binder for this cooperation. |
|
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: |
|
delete |
|
inline |
Get access to the layer with exception if layer is not found.
|
private |
Access to an additional layer.
|
inline |
Get access to the layer without raising exception if layer is not found.
|
inline |
Register single agent as a cooperation.
It is just a helper methods for convience.
Usage sample:
|
inline |
Register single agent as a cooperation with specified dispatcher binder.
It is just a helper methods for convience.
Usage sample:
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.
agent_coop | Cooperation to be registered. |
|
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. |
void so_5::environment_t::run | ( | ) |
Run the SObjectizer Run-Time.
|
private |
Auxiliary methods for getting reference to itself.
Could be used in constructors without compiler warnings.
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? |
disp_binder_shptr_t so_5::environment_t::so_make_default_disp_binder | ( | ) |
Get binding to the default dispatcher.
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. |
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. |
stats::controller_t & so_5::environment_t::stats_controller | ( | ) |
stats::repository_t & so_5::environment_t::stats_repository | ( | ) |
Access to repository of data sources for run-time monitoring.
void so_5::environment_t::stop | ( | ) |
Send a shutdown signal to the Run-Time.
work_thread_activity_tracking_t so_5::environment_t::work_thread_activity_tracking | ( | ) | const |
Get activity tracking flag for the whole SObjectizer Environment.
|
noexcept |
Access to the global work thread factory.
|
friend |
|
private |
SObjectizer Environment internals.