|
Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
|
Event dispatcher with exception handling and error recovery. More...
#include <safe_event_dispatcher.h>

Classes | |
| struct | dead_letter_entry |
Public Types | |
| using | error_callback = std::function<void(const handler_error_info&)> |
Public Member Functions | |
| safe_event_dispatcher (std::shared_ptr< interface_event_bus > bus=nullptr) | |
| template<typename EventType , typename Handler > | |
| uint64_t | subscribe_safe (Handler &&handler, event_priority priority=event_priority::normal) |
| Subscribe to events with automatic exception handling. | |
| template<typename EventType > | |
| bool | publish_safe (const EventType &event, event_priority priority=event_priority::normal) |
| Publish event with error recovery. | |
| void | set_error_callback (error_callback callback) |
| Set callback for handler errors. | |
| std::vector< handler_error_info > | get_handler_errors () const |
| Get recent handler errors. | |
| uint64_t | get_total_exceptions () const |
| Get total exception count. | |
| void | clear_errors () |
| Clear error history. | |
| void | set_circuit_breaker_threshold (size_t threshold) |
| Set circuit breaker threshold. | |
| size_t | get_dead_letter_queue_size () const |
| Get dead letter queue size. | |
| template<typename RecoveryHandler > | |
| void | process_dead_letters (RecoveryHandler &&handler) |
| Process dead letter queue with recovery handler. | |
| std::shared_ptr< interface_event_bus > | get_bus () const |
| Get underlying event bus. | |
Private Member Functions | |
| void | handle_exception (uint64_t handler_id, std::type_index event_type, const std::string &error_msg) |
| void | add_to_dead_letter_queue (std::type_index event_type, const std::string &error_msg) |
Private Attributes | |
| std::shared_ptr< interface_event_bus > | bus_ |
| std::atomic< uint64_t > | next_id_ {1} |
| std::atomic< uint64_t > | total_exceptions_ {0} |
| std::mutex | error_mutex_ |
| std::vector< handler_error_info > | recent_errors_ |
| std::unordered_map< uint64_t, size_t > | failed_handler_counts_ |
| error_callback | error_callback_ |
| size_t | circuit_breaker_threshold_ |
| std::mutex | dlq_mutex_ |
| std::vector< dead_letter_entry > | dead_letter_queue_ |
Event dispatcher with exception handling and error recovery.
Wraps event_bus to provide:
Definition at line 63 of file safe_event_dispatcher.h.
| using kcenon::monitoring::safe_event_dispatcher::error_callback = std::function<void(const handler_error_info&)> |
Definition at line 65 of file safe_event_dispatcher.h.
|
inlineexplicit |
Definition at line 67 of file safe_event_dispatcher.h.
|
inlineprivate |
Definition at line 262 of file safe_event_dispatcher.h.
References dead_letter_queue_, and dlq_mutex_.
Referenced by publish_safe().

|
inline |
Clear error history.
Definition at line 166 of file safe_event_dispatcher.h.
References error_mutex_, failed_handler_counts_, recent_errors_, and total_exceptions_.
|
inline |
|
inline |
Get dead letter queue size.
Definition at line 184 of file safe_event_dispatcher.h.
References dead_letter_queue_, and dlq_mutex_.
|
inline |
Get recent handler errors.
Definition at line 151 of file safe_event_dispatcher.h.
References error_mutex_, and recent_errors_.
|
inline |
Get total exception count.
Definition at line 159 of file safe_event_dispatcher.h.
References total_exceptions_.
|
inlineprivate |
Definition at line 221 of file safe_event_dispatcher.h.
References circuit_breaker_threshold_, error_callback_, error_mutex_, failed_handler_counts_, kcenon::monitoring::info, recent_errors_, and total_exceptions_.
Referenced by subscribe_safe().

|
inline |
Process dead letter queue with recovery handler.
Definition at line 193 of file safe_event_dispatcher.h.
References dead_letter_queue_, and dlq_mutex_.
|
inline |
Publish event with error recovery.
| event | Event to publish |
| priority | Event priority |
Definition at line 104 of file safe_event_dispatcher.h.
References add_to_dead_letter_queue(), bus_, error_callback_, and kcenon::monitoring::info.

|
inline |
Set circuit breaker threshold.
| threshold | Number of failures before handler is disabled |
Definition at line 177 of file safe_event_dispatcher.h.
References circuit_breaker_threshold_.
|
inline |
Set callback for handler errors.
Definition at line 143 of file safe_event_dispatcher.h.
References error_callback_, and error_mutex_.
|
inline |
Subscribe to events with automatic exception handling.
| handler | Event handler function |
| priority | Handler priority |
Definition at line 81 of file safe_event_dispatcher.h.
References bus_, handle_exception(), and next_id_.

|
private |
Definition at line 281 of file safe_event_dispatcher.h.
Referenced by get_bus(), publish_safe(), and subscribe_safe().
|
private |
Definition at line 289 of file safe_event_dispatcher.h.
Referenced by handle_exception(), and set_circuit_breaker_threshold().
|
private |
Definition at line 292 of file safe_event_dispatcher.h.
Referenced by add_to_dead_letter_queue(), get_dead_letter_queue_size(), and process_dead_letters().
|
mutableprivate |
Definition at line 291 of file safe_event_dispatcher.h.
Referenced by add_to_dead_letter_queue(), get_dead_letter_queue_size(), and process_dead_letters().
|
private |
Definition at line 288 of file safe_event_dispatcher.h.
Referenced by handle_exception(), publish_safe(), and set_error_callback().
|
mutableprivate |
Definition at line 285 of file safe_event_dispatcher.h.
Referenced by clear_errors(), get_handler_errors(), handle_exception(), and set_error_callback().
|
private |
Definition at line 287 of file safe_event_dispatcher.h.
Referenced by clear_errors(), and handle_exception().
|
private |
|
private |
Definition at line 286 of file safe_event_dispatcher.h.
Referenced by clear_errors(), get_handler_errors(), and handle_exception().
|
private |
Definition at line 283 of file safe_event_dispatcher.h.
Referenced by clear_errors(), get_total_exceptions(), and handle_exception().