|
Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
|
Thread-safe event bus implementation. More...
#include <event_bus.h>


Classes | |
| struct | stats |
Public Types | |
| using | config = event_bus_config |
Public Member Functions | |
| event_bus (const config &cfg=config()) | |
| ~event_bus () | |
| common::VoidResult | start () override |
| Start the event bus. | |
| common::VoidResult | stop () override |
| Stop the event bus. | |
| bool | is_active () const override |
| Check if event bus is active. | |
| size_t | get_pending_event_count () const override |
| Get pending event count. | |
| common::VoidResult | process_pending_events () override |
| Process all pending events synchronously. | |
| common::VoidResult | unsubscribe_event (const subscription_token &token) override |
| Unsubscribe from events using subscription token. | |
| stats | get_stats () const |
Public Member Functions inherited from kcenon::monitoring::interface_event_bus | |
| virtual | ~interface_event_bus ()=default |
| template<concepts::EventType E> | |
| common::VoidResult | publish_event (const E &event) |
| Publish an event to all subscribers. | |
| template<concepts::EventType E> | |
| common::Result< subscription_token > | subscribe_event (std::function< void(const E &)> handler, event_priority priority=event_priority::normal) |
| Subscribe to events of a specific type. | |
| template<concepts::EventType E, concepts::EventHandler< E > H> | |
| common::Result< subscription_token > | subscribe_event (H &&handler, event_priority priority=event_priority::normal) |
| Subscribe to events with a callable handler. | |
| template<concepts::EventType E> | |
| common::VoidResult | clear_subscriptions () |
| Clear all subscriptions for a specific event type. | |
| template<concepts::EventType E> | |
| size_t | get_subscriber_count () const |
| Get the number of subscribers for an event type. | |
Static Public Member Functions | |
| static std::shared_ptr< interface_event_bus > | instance () |
Protected Member Functions | |
| common::VoidResult | publish_event_impl (std::type_index event_type, std::any event) override |
| common::Result< subscription_token > | subscribe_event_impl (std::type_index event_type, std::function< void(const std::any &)> handler, uint64_t handler_id, event_priority priority) override |
| common::VoidResult | clear_subscriptions_impl (std::type_index event_type) override |
| size_t | get_subscriber_count_impl (std::type_index event_type) const override |
Protected Member Functions inherited from kcenon::monitoring::interface_event_bus | |
Private Member Functions | |
| void | process_events_worker () |
| void | process_all_pending () |
| void | dispatch_event (const event_envelope &envelope) |
Private Attributes | |
| config | config_ |
| std::mutex | bus_mutex_ |
| std::mutex | queue_mutex_ |
| std::mutex | handlers_mutex_ |
| std::priority_queue< event_envelope > | event_queue_ |
| std::unordered_map< std::type_index, std::vector< event_handler_wrapper > > | handlers_ |
| std::vector< std::thread > | workers_ |
| std::condition_variable | queue_cv_ |
| std::atomic< bool > | is_running_ |
| std::atomic< bool > | stop_requested_ |
| std::atomic< uint64_t > | total_events_published_ |
| std::atomic< uint64_t > | total_events_processed_ |
| std::atomic< uint64_t > | total_events_dropped_ |
Thread-safe event bus implementation.
Provides high-performance event distribution with:
Definition at line 146 of file event_bus.h.
Definition at line 148 of file event_bus.h.
Definition at line 150 of file event_bus.h.
References kcenon::monitoring::event_bus_config::auto_start, and config_.
|
inline |
Definition at line 160 of file event_bus.h.
References stop().

|
inlineoverrideprotectedvirtual |
Implements kcenon::monitoring::interface_event_bus.
Definition at line 347 of file event_bus.h.
References handlers_, and handlers_mutex_.
|
inlineprivate |
Definition at line 413 of file event_bus.h.
References handlers_, handlers_mutex_, kcenon::monitoring::event_envelope::payload, and kcenon::monitoring::event_envelope::type.
Referenced by process_all_pending(), and process_events_worker().

|
inlineoverridevirtual |
Get pending event count.
Implements kcenon::monitoring::interface_event_bus.
Definition at line 228 of file event_bus.h.
References event_queue_, and queue_mutex_.
|
inline |
Definition at line 272 of file event_bus.h.
References kcenon::monitoring::event_bus_config::back_pressure_threshold, config_, event_queue_, handlers_, handlers_mutex_, queue_mutex_, total_events_dropped_, total_events_processed_, and total_events_published_.
|
inlineoverrideprotectedvirtual |
Implements kcenon::monitoring::interface_event_bus.
Definition at line 354 of file event_bus.h.
References handlers_, and handlers_mutex_.
|
inlinestatic |
Definition at line 164 of file event_bus.h.
|
inlineoverridevirtual |
Check if event bus is active.
Implements kcenon::monitoring::interface_event_bus.
Definition at line 222 of file event_bus.h.
References bus_mutex_, and is_running_.
|
inlineprivate |
Definition at line 395 of file event_bus.h.
References dispatch_event(), event_queue_, kcenon::monitoring::pending, queue_mutex_, and total_events_processed_.
Referenced by process_pending_events(), and stop().


|
inlineprivate |
Definition at line 362 of file event_bus.h.
References config_, dispatch_event(), event_queue_, kcenon::monitoring::event_bus_config::processing_interval, queue_cv_, queue_mutex_, stop_requested_, and total_events_processed_.
Referenced by start().


|
inlineoverridevirtual |
Process all pending events synchronously.
Implements kcenon::monitoring::interface_event_bus.
Definition at line 234 of file event_bus.h.
References process_all_pending().

|
inlineoverrideprotectedvirtual |
Implements kcenon::monitoring::interface_event_bus.
Definition at line 298 of file event_bus.h.
References kcenon::monitoring::event_bus_config::back_pressure_threshold, config_, kcenon::monitoring::event_bus_config::enable_back_pressure, event_queue_, kcenon::monitoring::event_bus_config::max_queue_size, kcenon::monitoring::normal, queue_cv_, queue_mutex_, kcenon::monitoring::resource_exhausted, total_events_dropped_, and total_events_published_.
|
inlineoverridevirtual |
Start the event bus.
Implements kcenon::monitoring::interface_event_bus.
Definition at line 174 of file event_bus.h.
References kcenon::monitoring::already_started, bus_mutex_, config_, is_running_, process_events_worker(), stop_requested_, kcenon::monitoring::event_bus_config::worker_thread_count, and workers_.

|
inlineoverridevirtual |
Stop the event bus.
Implements kcenon::monitoring::interface_event_bus.
Definition at line 193 of file event_bus.h.
References bus_mutex_, is_running_, process_all_pending(), queue_cv_, stop_requested_, and workers_.
Referenced by ~event_bus().


|
inlineoverrideprotectedvirtual |
Implements kcenon::monitoring::interface_event_bus.
Definition at line 327 of file event_bus.h.
References handlers_, handlers_mutex_, and kcenon::monitoring::event_handler_wrapper::priority.
|
inlineoverridevirtual |
Unsubscribe from events using subscription token.
| token | The subscription token |
Implements kcenon::monitoring::interface_event_bus.
Definition at line 240 of file event_bus.h.
References kcenon::monitoring::subscription_token::get_event_type(), handlers_, and handlers_mutex_.

|
mutableprivate |
Definition at line 431 of file event_bus.h.
Referenced by is_active(), start(), and stop().
|
private |
Definition at line 430 of file event_bus.h.
Referenced by event_bus(), get_stats(), process_events_worker(), publish_event_impl(), and start().
|
private |
Definition at line 435 of file event_bus.h.
Referenced by get_pending_event_count(), get_stats(), process_all_pending(), process_events_worker(), and publish_event_impl().
|
private |
Definition at line 436 of file event_bus.h.
Referenced by clear_subscriptions_impl(), dispatch_event(), get_stats(), get_subscriber_count_impl(), subscribe_event_impl(), and unsubscribe_event().
|
mutableprivate |
Definition at line 433 of file event_bus.h.
Referenced by clear_subscriptions_impl(), dispatch_event(), get_stats(), get_subscriber_count_impl(), subscribe_event_impl(), and unsubscribe_event().
|
private |
Definition at line 441 of file event_bus.h.
Referenced by is_active(), start(), and stop().
|
private |
Definition at line 439 of file event_bus.h.
Referenced by process_events_worker(), publish_event_impl(), and stop().
|
mutableprivate |
Definition at line 432 of file event_bus.h.
Referenced by get_pending_event_count(), get_stats(), process_all_pending(), process_events_worker(), and publish_event_impl().
|
private |
Definition at line 442 of file event_bus.h.
Referenced by process_events_worker(), start(), and stop().
|
private |
Definition at line 446 of file event_bus.h.
Referenced by get_stats(), and publish_event_impl().
|
private |
Definition at line 445 of file event_bus.h.
Referenced by get_stats(), process_all_pending(), and process_events_worker().
|
private |
Definition at line 444 of file event_bus.h.
Referenced by get_stats(), and publish_event_impl().
|
private |
Definition at line 438 of file event_bus.h.