SObjectizer 5.8
Loading...
Searching...
No Matches
environment.cpp
Go to the documentation of this file.
1/*
2 SObjectizer 5.
3*/
4
5#include <so_5/environment.hpp>
6
7#include <string>
8
9#include <so_5/impl/internal_env_iface.hpp>
10#include <so_5/impl/coop_private_iface.hpp>
11
12#include <so_5/impl/mbox_core.hpp>
13#include <so_5/impl/layer_core.hpp>
14#include <so_5/impl/stop_guard_repo.hpp>
15#include <so_5/impl/std_msg_tracer_holder.hpp>
16
17#include <so_5/impl/run_stage.hpp>
18
19#include <so_5/stats/impl/std_controller.hpp>
20#include <so_5/stats/impl/ds_mbox_core_stats.hpp>
21#include <so_5/stats/impl/ds_agent_core_stats.hpp>
22#include <so_5/stats/impl/ds_timer_thread_stats.hpp>
23
24#include <so_5/env_infrastructures.hpp>
25
26#include <so_5/details/rollback_on_exception.hpp>
27
28namespace so_5
29{
30
31//
32// environment_params_t
33//
34
47
70
74
77{
78 environment_params_t tmp( std::move( other ) );
79 swap( *this, tmp );
80
81 return *this;
82}
83
84SO_5_FUNC void
115
118 so_5::timer_thread_factory_t factory )
119{
120 m_timer_thread_factory = std::move( factory );
121 return *this;
122}
123
126 coop_listener_unique_ptr_t coop_listener )
127{
128 m_coop_listener = std::move( coop_listener );
129 return *this;
130}
131
134 event_exception_logger_unique_ptr_t logger )
135{
136 if( nullptr != logger.get() )
137 m_event_exception_logger = std::move( logger );
138
139 return *this;
140}
141
142void
144 const std::type_index & type,
145 layer_unique_ptr_t layer_ptr )
146{
147 m_so_layers[ type ] = layer_ref_t( layer_ptr.release() );
148}
149
150namespace
151{
152
153/*!
154 * \brief A bunch of data sources for core objects.
155 *
156 * \since v.5.5.4
157 */
159 {
160 public :
162 outliving_reference_t< stats::repository_t > ds_repository,
163 impl::mbox_core_t & mbox_repository,
164 so_5::environment_infrastructure_t & infrastructure )
165 : m_mbox_repository( ds_repository, mbox_repository )
166 , m_coop_repository( ds_repository, infrastructure )
167 , m_timer_thread( ds_repository, infrastructure )
168 {}
169
170 private :
171 //! Data source for mboxes repository.
175
176 //! Data source for cooperations repository.
178 stats::impl::ds_agent_core_stats_t >
180
181 //! Data source for timer thread.
185 };
186
187/*!
188 * \brief Helper function for creation of appropriate manager
189 * object if necessary.
190 *
191 * \since v.5.5.18
192 */
193queue_locks_defaults_manager_unique_ptr_t
195 //! The current value. Note: can be nullptr.
196 queue_locks_defaults_manager_unique_ptr_t current )
197 {
198 queue_locks_defaults_manager_unique_ptr_t result( std::move(current) );
199
200 if( !result )
202
203 return result;
204 }
205
206//
207// default_event_queue_hook_t
208//
209/*!
210 * \brief Default implementation of event_queue_hook.
211 *
212 * Do nothing.
213 *
214 * \since v.5.5.24
215 */
216class default_event_queue_hook_t final : public event_queue_hook_t
217 {
218 public :
219 [[nodiscard]]
222 agent_t * /*agent*/,
223 event_queue_t * original_queue ) noexcept override
224 {
225 return original_queue;
226 }
227
228 void
230 agent_t * /*agent*/,
231 event_queue_t * /*queue*/ ) noexcept override
232 {
233 }
234 };
235
236/*!
237 * \brief Helper function for creation of appropriate event_queue_hook
238 * object if necessary.
239 *
240 * \since v.5.5.24
241 */
242[[nodiscard]]
243event_queue_hook_unique_ptr_t
245 //! The current value. Note: can be nullptr.
246 event_queue_hook_unique_ptr_t current )
247 {
248 event_queue_hook_unique_ptr_t result( std::move(current) );
249
250 if( !result )
251 result = make_event_queue_hook< default_event_queue_hook_t >(
253
254 return result;
255 }
256
257/*!
258 * \brief Helper function for creation of the default global work
259 * thread factory.
260 *
261 * If \a user_provided_factory is nullptr then standard work thread
262 * factory will be created. Otherwise \a user_provided_factory is
263 * returned.
264 *
265 * \since v.5.7.3
266 */
267[[nodiscard]]
268so_5::disp::abstract_work_thread_factory_shptr_t
270 //! The current value provided by a user. Note: it can be nullptr.
271 so_5::disp::abstract_work_thread_factory_shptr_t user_provided_factory )
272 {
273 so_5::disp::abstract_work_thread_factory_shptr_t result{
274 std::move(user_provided_factory)
275 };
276
277 if( !result )
279
280 return result;
281 }
282
283/*!
284 * \brief Helper function for creation of the default subscription storage
285 * factory.
286 *
287 * If \a user_provided_factory is nullptr then standard default subscription
288 * storage factory will be returned. Otherwise \a user_provided_factory is
289 * returned.
290 *
291 * \since v.5.8.2
292 */
293[[nodiscard]]
294so_5::subscription_storage_factory_t
296 //! The current value provided by a user. Note: it can be nullptr.
297 subscription_storage_factory_t user_provided_factory )
298 {
299 if( !user_provided_factory )
300 user_provided_factory = default_subscription_storage_factory();
301
302 return user_provided_factory;
303 }
304
305} /* namespace anonymous */
306
307//
308// environment_t::internals_t
309//
310/*!
311 * \since v.5.5.0
312 *
313 * \brief Internal details of SObjectizer Environment object.
314 */
316{
317 /*!
318 * \brief Error logger object for this environment.
319 *
320 * \attention Must be the first attribute of the object!
321 * It must be created and initilized first and destroyed last.
322 *
323 * \since v.5.5.0
324 */
325 error_logger_shptr_t m_error_logger;
326
327 /*!
328 * \brief Holder of stuff related to message delivery tracing.
329 *
330 * \attention This field must be declared and initialized
331 * before m_mbox_core because a reference to that object will be passed
332 * to the constructor of m_mbox_core.
333 *
334 * \since v.5.5.22
335 */
337
338 //! An utility for mboxes.
339 impl::mbox_core_ref_t m_mbox_core;
340
341 /*!
342 * \brief A repository of stop_guards.
343 *
344 * \since v.5.5.19.2
345 */
347
348 /*!
349 * \brief A specific infrastructure for environment.
350 *
351 * Note: infrastructure takes care about coop repository,
352 * timer threads/managers and default dispatcher.
353 *
354 * \since v.5.5.19
355 */
356 environment_infrastructure_unique_ptr_t m_infrastructure;
357
358 //! An utility for layers.
360
361 /*!
362 * \brief An exception reaction for the whole SO Environment.
363 *
364 * \since v.5.3.0
365 */
367
368 /*!
369 * \brief Is autoshutdown when there is no more cooperation disabled?
370 *
371 * \see environment_params_t::disable_autoshutdown()
372 *
373 * \since v.5.4.0
374 */
376
377 /*!
378 * \brief Data sources for core objects.
379 *
380 * \attention This instance must be created after stats_controller
381 * and destroyed before it. Because of that m_core_data_sources declared
382 * after m_stats_controller and after all corresponding objects.
383 * NOTE: since v.5.5.19 stats_controller and stats_repository are parts
384 * of environment_infrastructure. Because of that m_core_data_sources
385 * declared and created after m_infrastructure.
386 *
387 * \since v.5.5.4
388 */
390
391 /*!
392 * \brief Work thread activity tracking for the whole Environment.
393 *
394 * \since v.5.5.18
395 */
397
398 /*!
399 * \brief Manager for defaults of queue locks.
400 *
401 * \since v.5.5.18
402 */
403 queue_locks_defaults_manager_unique_ptr_t m_queue_locks_defaults_manager;
404
405 /*!
406 * \brief Actual event_queue_hook.
407 *
408 * \note
409 * If there is no event_queue_hook in environment_params_t then
410 * an instance of default_event_queue_hook_t will be created and used.
411 *
412 * \since v.5.5.24
413 */
414 event_queue_hook_unique_ptr_t m_event_queue_hook;
415
416 /*!
417 * \brief Actual global work thread factory.
418 *
419 * \note
420 * If there is no work_thread_factory in environment_params_t then
421 * an instance of the standard work thread factory will be created
422 * and used.
423 *
424 * \since v.5.7.3
425 */
426 so_5::disp::abstract_work_thread_factory_shptr_t m_work_thread_factory;
427
428 /*!
429 * \brief Lock object for protection of exception logger object.
430 *
431 * \note
432 * Manipulations with m_event_exception_logger are performed
433 * only under that lock.
434 *
435 * \since v.5.6.0
436 */
438
439 /*!
440 * \brief Logger for exceptions thrown from event-handlers.
441 *
442 * \since v.5.6.0
443 */
444 event_exception_logger_unique_ptr_t m_event_exception_logger;
445
446 /*!
447 * \brief Factory to be used as default subscription storage factory.
448 *
449 * \note
450 * It can't be null. This has to be checked in the constructor.
451 *
452 * \since v.5.8.2
453 */
454 subscription_storage_factory_t m_default_subscription_storage_factory;
455
456 //! Constructor.
458 environment_t & env,
459 environment_params_t && params )
465 new impl::mbox_core_t{
469 env,
470 params,
471 // A special mbox for distributing monitoring information
472 // must be created and passed to stats_controller.
475 env,
499 {}
500};
501
502//
503// environment_t
504//
505
508{
509 return *this;
510}
511
512
514 environment_params_t && params )
515 : m_impl( new internals_t( self_ref(), std::move(params) ) )
516{
517}
518
522
523mbox_t
528
529mbox_t
531 nonempty_name_t nonempty_name )
532{
533 return m_impl->m_mbox_core->create_mbox( *this, std::move(nonempty_name) );
534}
535
536mbox_t
538 mbox_namespace_name_t mbox_namespace,
539 nonempty_name_t mbox_name,
540 const std::function< mbox_t() > & mbox_factory )
541{
543 std::move(mbox_namespace),
544 std::move(mbox_name),
545 mbox_factory );
546}
547
548mchain_t
550 const mchain_params_t & params )
551{
552 return m_impl->m_mbox_core->create_mchain( *this, params );
553}
554
555void
557 event_exception_logger_unique_ptr_t logger )
558{
559 if( logger )
560 {
561 std::lock_guard< std::mutex > lock{
563
564 using std::swap;
565 swap( m_impl->m_event_exception_logger, logger );
566
567 m_impl->m_event_exception_logger->on_install( std::move( logger ) );
568 }
569}
570
571[[nodiscard]]
579
580[[nodiscard]]
583 disp_binder_shptr_t disp_binder )
584{
586 coop_handle_t{}, // No parent.
587 std::move(disp_binder) );
588}
589
590[[nodiscard]]
593 coop_handle_t parent )
594{
596 std::move(parent),
598}
599
600[[nodiscard]]
603 coop_handle_t parent,
604 disp_binder_shptr_t disp_binder )
605{
607 std::move(parent),
608 std::move(disp_binder) );
609}
610
613 coop_unique_holder_t agent_coop )
614{
615 return m_impl->m_infrastructure->register_coop( std::move( agent_coop ) );
616}
617
621{
622 // Since v.5.5.21 pause and period should be checked for negative
623 // values.
624 using duration = std::chrono::steady_clock::duration;
625 if( params.m_pause < duration::zero() )
628 "an attempt to call schedule_timer() with negative pause value" );
629 if( params.m_period < duration::zero() )
632 "an attempt to call schedule_timer() with negative period value" );
633
634 // If it is a mutable message then there must be some restrictions:
636 {
637 // Mutable message can be sent only as delayed message.
638 if( std::chrono::steady_clock::duration::zero() != params.m_period )
641 "unable to schedule periodic timer for mutable message,"
642 " msg_type=" + std::string(params.m_msg_type.name()) );
643 // Mutable message can't be passed to MPMC-mbox.
647 "unable to schedule timer for mutable message and "
648 "MPMC mbox, msg_type=" + std::string(params.m_msg_type.name()) );
649 }
650
652 params.m_msg_type,
653 params.m_msg,
654 params.m_mbox,
655 params.m_pause,
656 params.m_period );
657}
658
659void
662{
663 // Since v.5.5.21 pause should be checked for negative values.
664 using duration = std::chrono::steady_clock::duration;
665 if( params.m_pause < duration::zero() )
668 "an attempt to call single_timer() with negative pause value" );
669
670 // Mutable message can't be passed to MPMC-mbox.
675 "unable to schedule single timer for mutable message and "
676 "MPMC mbox, msg_type=" + std::string(params.m_msg_type.name()) );
677
679 params.m_msg_type,
680 params.m_msg,
681 params.m_mbox,
682 params.m_pause );
683}
684
685layer_t *
687 const std::type_index & type ) const
688{
690}
691
692void
694 const std::type_index & type,
695 const layer_ref_t & layer )
696{
698}
699
700void
702{
703 try
704 {
706 }
707 catch( const so_5::exception_t & )
708 {
709 // Rethrow our exception because it already has all information.
710 throw;
711 }
712 catch( const std::exception & x )
713 {
716 std::string( "some unexpected error during "
717 "environment launching: " ) + x.what() );
718 }
719}
720
721void
723{
724 // Since v.5.5.19.2 there is a new shutdown procedure:
725 const auto action = m_impl->m_stop_guards.initiate_stop();
728}
729
730void
732 const std::exception & event_exception,
733 const coop_handle_t & coop ) noexcept
734{
735 std::lock_guard< std::mutex > lock{ m_impl->m_event_exception_logger_lock };
736
737 m_impl->m_event_exception_logger->log_exception( event_exception, coop );
738}
739
742{
744}
745
748{
749 return *(m_impl->m_error_logger);
750}
751
757
763
764so_5::disp::abstract_work_thread_factory_shptr_t
766{
768}
769
775
776disp_binder_shptr_t
781
782bool
787
788mbox_t
794
797 stop_guard_shptr_t guard,
798 stop_guard_t::what_if_stop_in_progress_t reaction_on_stop_in_progress )
799{
800 const auto result = m_impl->m_stop_guards.setup_guard( std::move(guard) );
803 reaction_on_stop_in_progress )
804 {
807 "stop_guard can't be set because the stop operation is "
808 "already in progress" );
809 }
810
811 return result;
812}
813
814void
816 stop_guard_shptr_t guard )
817{
818 const auto action = m_impl->m_stop_guards.remove_guard( std::move(guard) );
821}
822
823void
825 so_5::msg_tracing::filter_shptr_t filter )
826{
830 "msg_tracing's filter can't be changed when msg_tracing "
831 "is disabled" );
832
834}
835
836void
838{
840 "run_stats_controller",
841 [] {
842 /* there is no need to turn_on controller automatically */
843 },
846}
847
848void
857
858namespace
859{
860 class autoshutdown_guard_t final
861 {
865
866 public :
868 environment_t & env,
869 bool autoshutdown_disabled )
870 : m_env{ env }
871 , m_autoshutdown_disabled{ autoshutdown_disabled }
872 {
874 {
876 }
877 }
878
884 };
885
886} /* namespace anonymous */
887
888void
890{
892 [this]()
893 {
894 // init method must be protected from autoshutdown feature.
895 autoshutdown_guard_t guard{
896 *this,
898
899 // Initilizing environment.
900 init();
901 } );
902}
903
904namespace impl
905{
906
907mbox_t
909 agent_t & single_consumer )
910{
912 m_env,
913 single_consumer );
914}
915
916mbox_t
918 agent_t & single_consumer )
919{
921 m_env,
922 single_consumer );
923}
924
925void
927 coop_shptr_t coop ) noexcept
928{
930}
931
932void
934 coop_shptr_t coop ) noexcept
935{
936 bool any_cooperation_alive =
938 std::move(coop) );
939
940 if( !any_cooperation_alive && !m_env.m_impl->m_autoshutdown_disabled )
942}
943
944bool
949
952{
955 "msg_tracer cannot be accessed because msg_tracing is disabled" );
956
958}
959
965
966so_5::disp::mpsc_queue_traits::lock_factory_t
972
973so_5::disp::mpmc_queue_traits::lock_factory_t
979
980[[nodiscard]]
983 agent_t * agent,
984 event_queue_t * original_queue ) noexcept
985{
986 return m_env.m_impl->m_event_queue_hook->on_bind( agent, original_queue );
987}
988
989void
991 agent_t * agent,
992 event_queue_t * queue ) noexcept
993{
995}
996
997[[nodiscard]] mbox_id_t
1002
1003[[nodiscard]] subscription_storage_factory_t
1009
1010} /* namespace impl */
1011
1012} /* namespace so_5 */
virtual mbox_type_t type() const =0
Get the type of message box.
A base class for agents.
Definition agent.hpp:673
autoshutdown_guard_t(environment_t &env, bool autoshutdown_disabled)
stats::auto_registered_source_holder_t< stats::impl::ds_timer_thread_stats_t > m_timer_thread
Data source for timer thread.
stats::auto_registered_source_holder_t< stats::impl::ds_agent_core_stats_t > m_coop_repository
Data source for cooperations repository.
stats::auto_registered_source_holder_t< stats::impl::ds_mbox_core_stats_t > m_mbox_repository
Data source for mboxes repository.
core_data_sources_t(outliving_reference_t< stats::repository_t > ds_repository, impl::mbox_core_t &mbox_repository, so_5::environment_infrastructure_t &infrastructure)
event_queue_t * on_bind(agent_t *, event_queue_t *original_queue) noexcept override
A reaction to binding of an agent to some event_queue.
void on_unbind(agent_t *, event_queue_t *) noexcept override
A reaction to unbinding of an agent from some event_queue.
Type of smart handle for a cooperation.
A special type that plays role of unique_ptr for coop.
Definition coop.hpp:1342
Interface for creator of new mbox in OOP style.
Alias for namespace with traits of event queue.
disp_params_t()=default
Default constructor.
An interface for environment_infrastructure entity.
virtual::so_5::stats::repository_t & stats_repository() noexcept=0
Get stats repository for the environment.
virtual coop_unique_holder_t make_coop(coop_handle_t parent, disp_binder_shptr_t default_binder)=0
Create an instance of a new coop.
virtual bool final_deregister_coop(coop_shptr_t coop) noexcept=0
Do final actions of the cooperation deregistration.
virtual void launch(env_init_t init_fn)=0
Do actual launch of SObjectizer's Environment.
virtual void ready_to_deregister_notify(coop_shptr_t coop) noexcept=0
virtual::so_5::stats::controller_t & stats_controller() noexcept=0
Get stats controller for the environment.
virtual so_5::timer_id_t schedule_timer(const std::type_index &type_wrapper, const message_ref_t &msg, const mbox_t &mbox, std::chrono::steady_clock::duration pause, std::chrono::steady_clock::duration period)=0
Initiate a timer (delayed or periodic message).
virtual void stop() noexcept=0
Initiate a signal for shutdown of Environment.
virtual coop_handle_t register_coop(coop_unique_holder_t coop)=0
Register new cooperation.
virtual disp_binder_shptr_t make_default_disp_binder()=0
Create a binder for the default dispatcher.
virtual void single_timer(const std::type_index &type_wrapper, const message_ref_t &msg, const mbox_t &mbox, std::chrono::steady_clock::duration pause)=0
Initiate a delayed message.
Parameters for the SObjectizer Environment initialization.
event_queue_hook_unique_ptr_t m_event_queue_hook
An event_queue_hook object.
layer_map_t m_so_layers
Additional layers.
so_5::disp::abstract_work_thread_factory_shptr_t so5_giveout_work_thread_factory()
Take out work_thread_factory object.
environment_infrastructure_factory_t m_infrastructure_factory
A factory for environment infrastructure entity.
environment_params_t & event_exception_logger(event_exception_logger_unique_ptr_t logger)
Set exception logger object.
bool m_autoshutdown_disabled
Is autoshutdown when there is no more cooperation disabled?
queue_locks_defaults_manager_unique_ptr_t so5_giveout_queue_locks_defaults_manager()
Take out queue locks defaults manager.
default_disp_params_t m_default_disp_params
Parameters for the default dispatcher.
void add_layer(const std::type_index &type, layer_unique_ptr_t layer_ptr)
Add an additional layer.
bool autoshutdown_disabled() const
Is autoshutdown disabled?
so_5::msg_tracing::tracer_unique_ptr_t so5_giveout_message_delivery_tracer()
Get message delivery tracer for the environment.
so_5::msg_tracing::filter_shptr_t so5_giveout_message_delivery_tracer_filter()
Get message delivery tracer filter for the environment.
queue_locks_defaults_manager_unique_ptr_t m_queue_locks_defaults_manager
Manager for defaults of queue locks.
environment_params_t(environment_params_t &&other)
Move constructor.
const environment_infrastructure_factory_t & infrastructure_factory() const
Get the current environment infrastructure factory.
friend SO_5_FUNC void swap(environment_params_t &a, environment_params_t &b) noexcept
Swap operation.
environment_params_t & coop_listener(coop_listener_unique_ptr_t coop_listener)
Set cooperation listener object.
layer_map_t so5_giveout_layers_map()
Get map of default SObjectizer's layers.
so_5::msg_tracing::tracer_unique_ptr_t m_message_delivery_tracer
Tracer for message delivery.
exception_reaction_t exception_reaction() const noexcept
Get exception reaction flag value.
error_logger_shptr_t m_error_logger
Error logger for the environment.
subscription_storage_factory_t m_default_subscription_storage_factory
Default subscription storage factory.
so_5::disp::abstract_work_thread_factory_shptr_t m_work_thread_factory
Global factory for work threads.
environment_params_t()
Constructor.
event_exception_logger_unique_ptr_t m_event_exception_logger
Exception logger.
event_queue_hook_unique_ptr_t so5_giveout_event_queue_hook()
Take out event_queue_hook object.
so_5::msg_tracing::filter_shptr_t m_message_delivery_tracer_filter
Message delivery tracer filter to be used with environment.
work_thread_activity_tracking_t work_thread_activity_tracking() const
Get activity tracking flag for the whole SObjectizer Environment.
const error_logger_shptr_t & so5_error_logger() const
Get error logger for the environment.
environment_params_t & operator=(environment_params_t &&other) noexcept
Move operator.
event_exception_logger_unique_ptr_t so5_giveout_event_exception_logger()
Get exception logger.
coop_listener_unique_ptr_t m_coop_listener
Cooperation listener.
environment_params_t & timer_thread(so_5::timer_thread_factory_t factory)
Set the timer_thread factory.
exception_reaction_t m_exception_reaction
Exception reaction flag for the whole SO Environment.
work_thread_activity_tracking_t m_work_thread_activity_tracking
Work thread activity tracking for the whole Environment.
const subscription_storage_factory_t & default_subscription_storage_factory() const noexcept
Get the current default subscription storage factory.
so_5::timer_thread_factory_t m_timer_thread_factory
Timer thread factory.
SObjectizer Environment.
disp_binder_shptr_t so_make_default_disp_binder()
Get binding to the default dispatcher.
mbox_t create_mbox()
Create an anonymous MPMC mbox.
error_logger_t & error_logger() const
Get the error_logger object.
void imp_run_layers_and_go_further()
Run layers and call next run stage.
void add_extra_layer(const std::type_index &type, const layer_ref_t &layer)
Add an additional layer.
so_5::timer_id_t so_schedule_timer(const low_level_api::schedule_timer_params_t params)
Schedule timer event.
stats::repository_t & stats_repository()
Access to repository of data sources for run-time monitoring.
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.
void install_exception_logger(event_exception_logger_unique_ptr_t logger)
Set up an exception logger.
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.
void run()
Run the SObjectizer Run-Time.
mchain_t create_mchain(const mchain_params_t &params)
Create message chain.
exception_reaction_t exception_reaction() const noexcept
An exception reaction for the whole SO Environment.
std::unique_ptr< internals_t > m_impl
SObjectizer Environment internals.
environment_t & self_ref()
Auxiliary methods for getting reference to itself.
coop_unique_holder_t make_coop(coop_handle_t parent)
Create a new cooperation that will be a child for specified parent coop.
so_5::disp::abstract_work_thread_factory_shptr_t work_thread_factory() const noexcept
Access to the global work thread factory.
void call_exception_logger(const std::exception &event_exception, const coop_handle_t &coop) noexcept
Call event exception logger for logging an exception.
environment_t(environment_params_t &&so_environment_params)
stats::controller_t & stats_controller()
Access to controller of run-time monitoring.
layer_t * query_layer(const std::type_index &type) const
Access to an additional layer.
void imp_run_infrastructure()
Launch environment infrastructure and wait for finish.
void imp_run_stats_controller_and_go_further()
Run controller for run-time monitoring and call next run stage.
coop_unique_holder_t make_coop()
Create a cooperation.
void stop() noexcept
Send a shutdown signal to the Run-Time.
work_thread_activity_tracking_t work_thread_activity_tracking() const
Get activity tracking flag for the whole SObjectizer Environment.
mbox_t do_make_custom_mbox(custom_mbox_details::creator_iface_t &creator)
Actual creation of a custom mbox.
void remove_stop_guard(stop_guard_shptr_t guard)
Remove stop_guard and complete the stop operation if necessary.
coop_handle_t register_coop(coop_unique_holder_t agent_coop)
Register a cooperation.
void deregister_coop(coop_handle_t coop, int reason) noexcept
Deregister the cooperation.
coop_unique_holder_t make_coop(disp_binder_shptr_t disp_binder)
Create a cooperation with specified dispatcher binder.
virtual void init()=0
Initialization hook.
mbox_t create_mbox(nonempty_name_t mbox_name)
Create named MPMC mbox.
void so_single_timer(const low_level_api::single_timer_params_t params)
Schedule a single shot timer event.
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.
bool autoshutdown_disabled() const
Get autoshutdown_disabled flag.
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.
An interface for logging error messages.
virtual void on_install(event_exception_logger_unique_ptr_t previous_logger) noexcept
Installation hook.
virtual void log_exception(const std::exception &event_exception, const coop_handle_t &coop) noexcept=0
Log the exception caught.
Interface of event_queue_hook object.
virtual event_queue_t * on_bind(agent_t *agent, event_queue_t *original_queue) noexcept=0
A reaction to binding of an agent to some event_queue.
static void default_deleter(event_queue_hook_t *what) noexcept
An implementation of deleter that use operator delete for destroying object of type event_queue_hook.
virtual void on_unbind(agent_t *agent, event_queue_t *queue) noexcept=0
A reaction to unbinding of an agent from some event_queue.
An interface of event queue for agent.
The base class for all SObjectizer exceptions.
Definition exception.hpp:34
A helper class for accessing the functionality of environment-class which is specific for SObjectizer...
mbox_id_t allocate_mbox_id() noexcept
Allocate a new ID for a new custom mbox or mchain.
event_queue_t * event_queue_on_bind(agent_t *agent, event_queue_t *original_queue) noexcept
Call the event_queue_hook when an agent is being bound to a particular event_queue.
so_5::disp::mpmc_queue_traits::lock_factory_t default_mpmc_queue_lock_factory() const
Get default lock_factory for MPMC queues.
so_5::msg_tracing::holder_t & msg_tracing_stuff() const
Get access to message delivery tracer stuff holder.
subscription_storage_factory_t default_subscription_storage_factory() const noexcept(noexcept(subscription_storage_factory_t{}=subscription_storage_factory_t{}))
Get the default storage subscription factory.
environment_t & m_env
Environment instance to work with.
void event_queue_on_unbind(agent_t *agent, event_queue_t *queue) noexcept
Call the event_queue_hook when an agent is being unbound from its event_queue.
mbox_t create_ordinary_mpsc_mbox(agent_t &single_consumer)
Create multi-producer/single-consumer mbox that handles message limits.
bool is_msg_tracing_enabled() const
Is message delivery tracing enabled?
so_5::msg_tracing::holder_t & msg_tracing_stuff_nonchecked() const noexcept
Get access to message delivery tracer stuff holder.
so_5::disp::mpsc_queue_traits::lock_factory_t default_mpsc_queue_lock_factory() const
Get default lock_factory for MPSC queues.
void final_deregister_coop(coop_shptr_t coop) noexcept
Do the final actions of a cooperation deregistration.
mbox_t create_limitless_mpsc_mbox(agent_t &single_consumer)
Create multi-producer/single-consumer mbox that ignores message limits.
void ready_to_deregister_notify(coop_shptr_t coop) noexcept
Notification about readiness to the deregistration.
An utility class for working with layers.
layer_t * query_layer(const std::type_index &type) const
Get a layer.
void add_extra_layer(const std::type_index &type, const layer_ref_t &layer)
Add an extra layer.
void start()
Start all layers.
layer_core_t(environment_t &env, layer_map_t &&so_layers)
void finish()
Shutdown all layers and wait for full stop of them.
mbox_t create_ordinary_mpsc_mbox(environment_t &env, agent_t &owner)
Create mpsc_mbox that handles message limits.
mbox_t create_limitless_mpsc_mbox(environment_t &env, agent_t &owner)
Create mpsc_mbox that ignores message limits.
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.
mbox_core_t(outliving_reference_t< so_5::msg_tracing::holder_t > msg_tracing_stuff)
Definition mbox_core.cpp:27
mbox_t create_custom_mbox(environment_t &env, ::so_5::custom_mbox_details::creator_iface_t &creator)
Create a custom mbox.
mchain_t create_mchain(environment_t &env, const mchain_params_t &params)
Create message chain.
mbox_t create_mbox(environment_t &env)
Create local anonymous mbox.
Definition mbox_core.cpp:35
mbox_t create_mbox(environment_t &env, nonempty_name_t mbox_name)
Create local named mbox.
Definition mbox_core.cpp:46
mbox_id_t allocate_mbox_id() noexcept
Allocate an ID for a new custom mbox or mchain.
stop_guard_t::setup_result_t setup_guard(stop_guard_shptr_t guard)
Setup new stop_guard.
action_t remove_guard(stop_guard_shptr_t guard) noexcept
Remove stop_guard.
action_t initiate_stop() noexcept
Initiate stop operation.
action_t
Action which must be performed as result of operation on repository.
@ do_actual_stop
Stop operation must be finished.
intrusive_ptr_t(T *obj) noexcept
Constructor for a raw pointer.
intrusive_ptr_t(intrusive_ptr_t &&o) noexcept
Move constructor.
T * operator->() const noexcept
T & operator*() const noexcept
friend void swap(intrusive_ptr_t &a, intrusive_ptr_t &b) noexcept
Swap values.
An interface of the additional SObjectizer Environment layer.
Definition so_layer.hpp:31
A class for the name of mbox_namespace.
Parameters for message chain.
Definition mchain.hpp:729
friend message_mutability_t message_mutability(const intrusive_ptr_t< message_t > &what) noexcept
Helper method for safe get of message mutability flag.
Definition message.hpp:74
Interface of holder of message tracer and message trace filter objects.
Standard implementation of message tracer holder.
std_holder_t(filter_shptr_t filter, tracer_unique_ptr_t tracer)
Initializing constructor.
void change_filter(filter_shptr_t filter) noexcept
virtual bool is_msg_tracing_enabled() const noexcept override
Is message tracing enabled?
A class for the name which cannot be empty.
Helper class for indication of long-lived reference via its type.
Definition outliving.hpp:98
virtual so_5::disp::mpsc_queue_traits::lock_factory_t mpsc_queue_lock_factory()=0
Get default lock_factory for MPSC queues.
virtual so_5::disp::mpmc_queue_traits::lock_factory_t mpmc_queue_lock_factory()=0
Get default lock_factory for MPMC queues.
A holder for data-souce that should be automatically registered and deregistered in registry.
A public interface for control SObjectizer monitoring options.
virtual void turn_off()=0
Turn the monitoring off.
A data source for distributing information about mbox_core.
A data source for distributing information about timer_thread.
An interface of data sources repository.
An interface of stop_guard entity.
setup_result_t
Type for result of setting up a new stop_guard.
@ throw_exception
An exception must be thrown.
An indentificator for the timer.
Definition timers.hpp:73
#define SO_5_FUNC
Definition declspec.hpp:48
#define SO_5_THROW_EXCEPTION(error_code, desc)
Definition exception.hpp:74
so_5::subscription_storage_factory_t ensure_subscription_storage_factory_exists(subscription_storage_factory_t user_provided_factory)
Helper function for creation of the default subscription storage factory.
so_5::disp::abstract_work_thread_factory_shptr_t ensure_work_thread_factory_exists(so_5::disp::abstract_work_thread_factory_shptr_t user_provided_factory)
Helper function for creation of the default global work thread factory.
queue_locks_defaults_manager_unique_ptr_t ensure_locks_defaults_manager_exists(queue_locks_defaults_manager_unique_ptr_t current)
Helper function for creation of appropriate manager object if necessary.
event_queue_hook_unique_ptr_t ensure_event_queue_hook_exists(event_queue_hook_unique_ptr_t current)
Helper function for creation of appropriate event_queue_hook object if necessary.
Enumeration of cooperation deregistration reasons.
Definition coop.hpp:39
const int normal
Normal deregistration.
Definition coop.hpp:46
Various stuff related to MPMC event queue implementation and tuning.
Various stuff related to MPSC event queue implementation and tuning.
Dispatcher with single working thread.
Event dispatchers.
SO_5_FUNC abstract_work_thread_factory_shptr_t make_std_work_thread_factory()
Get a standard SObjectizer's work thread factory that is used by default.
Default multi-threaded environment infrastructure.
SO_5_FUNC environment_infrastructure_factory_t factory()
A factory for creation the default multitheading environment infrastructure.
Various implementations of environment_infrastructure.
Details of SObjectizer run-time implementations.
Definition agent.cpp:780
void run_stage(const std::string &stage_name, Init_Fn &&init_fn, Deinit_Fn &&deinit_fn, Next_Stage &&next_stage)
Helper template function for doing initialization phase with rollback on failure.
Definition run_stage.hpp:31
Implementation details of message delivery tracing mechanism.
Public part of message delivery tracing mechanism.
Internal implementation of run-time monitoring and statistics related stuff.
All stuff related to run-time monitoring and statistics.
Private part of message limit implementation.
Definition agent.cpp:33
event_queue_hook_unique_ptr_t make_event_queue_hook(event_queue_hook_deleter_fnptr_t deleter, Args &&...args)
Helper function for simplify creation of event_queue_hook object.
SO_5_FUNC queue_locks_defaults_manager_unique_ptr_t make_defaults_manager_for_combined_locks()
A factory for queue_locks_defaults_manager with generators for combined locks.
SO_5_FUNC subscription_storage_factory_t default_subscription_storage_factory()
Factory for default subscription storage object.
mbox_type_t
Type of the message box.
Definition mbox.hpp:163
const int rc_negative_value_for_pause
An attempt to use negative value for pause argument for delayed or periodic message/signal.
Definition ret_code.hpp:270
const int rc_mutable_msg_cannot_be_periodic
An attempt to send mutable message as a periodic message.
Definition ret_code.hpp:241
const int rc_cannot_set_stop_guard_when_stop_is_started
An attempt to set up a new stop_guard when the stop operation is already in progress.
Definition ret_code.hpp:259
exception_reaction_t
A reaction of SObjectizer to an exception from agent event.
Definition agent.hpp:65
@ abort_on_exception
Execution of application must be aborted immediatelly.
Definition agent.hpp:67
SO_5_FUNC error_logger_shptr_t create_stderr_logger()
A factory for creating error_logger implemenation which uses std::stderr as log stream.
message_mutability_t
A enum with variants of message mutability or immutability.
Definition types.hpp:94
event_queue_hook_unique_ptr_t make_empty_event_queue_hook_unique_ptr()
Helper function for creation of empty unique_ptr for event_queue_hook.
work_thread_activity_tracking_t
Values for dispatcher's work thread activity tracking.
Definition types.hpp:75
@ unspecified
Tracking mode is specified elsewhere.
const int rc_msg_tracing_disabled
Message delivery tracing is disabled and cannot be used.
Definition ret_code.hpp:182
const int rc_environment_error
so_environment launch is failed.
Definition ret_code.hpp:24
const int rc_mutable_msg_cannot_be_delivered_via_mpmc_mbox
An attempt to deliver mutable message via MPMC mbox.
Definition ret_code.hpp:234
SO_5_FUNC event_exception_logger_unique_ptr_t create_std_event_exception_logger()
Create the default exception logger.
const int rc_negative_value_for_period
An attempt to use negative value for period argument for periodic message/signal.
Definition ret_code.hpp:280
outliving_reference_t< T > outliving_mutable(T &r)
Make outliving_reference wrapper for mutable reference.
Internal details of SObjectizer Environment object.
so_5::msg_tracing::impl::std_holder_t m_msg_tracing_stuff
Holder of stuff related to message delivery tracing.
const exception_reaction_t m_exception_reaction
An exception reaction for the whole SO Environment.
const bool m_autoshutdown_disabled
Is autoshutdown when there is no more cooperation disabled?
core_data_sources_t m_core_data_sources
Data sources for core objects.
impl::layer_core_t m_layer_core
An utility for layers.
event_exception_logger_unique_ptr_t m_event_exception_logger
Logger for exceptions thrown from event-handlers.
impl::mbox_core_ref_t m_mbox_core
An utility for mboxes.
impl::stop_guard_repository_t m_stop_guards
A repository of stop_guards.
environment_infrastructure_unique_ptr_t m_infrastructure
A specific infrastructure for environment.
internals_t(environment_t &env, environment_params_t &&params)
Constructor.
error_logger_shptr_t m_error_logger
Error logger object for this environment.
std::mutex m_event_exception_logger_lock
Lock object for protection of exception logger object.
event_queue_hook_unique_ptr_t m_event_queue_hook
Actual event_queue_hook.
queue_locks_defaults_manager_unique_ptr_t m_queue_locks_defaults_manager
Manager for defaults of queue locks.
work_thread_activity_tracking_t m_work_thread_activity_tracking
Work thread activity tracking for the whole Environment.
so_5::disp::abstract_work_thread_factory_shptr_t m_work_thread_factory
Actual global work thread factory.
subscription_storage_factory_t m_default_subscription_storage_factory
Factory to be used as default subscription storage factory.
const mbox_t & m_mbox
Mbox to which message will be delivered.
const message_ref_t & m_msg
Message to be sent after timeout.
std::chrono::steady_clock::duration m_period
Period of the delivery repetition for periodic messages.
std::chrono::steady_clock::duration m_pause
Timeout before the first delivery.
const std::type_index & m_msg_type
Message type.
const mbox_t & m_mbox
Mbox to which message will be delivered.
const std::type_index & m_msg_type
Message type.
std::chrono::steady_clock::duration m_pause
Timeout before the delivery.
const message_ref_t & m_msg
Message to be sent after timeout.