Raxol.Core.Events.EventManager.EventManagerServer (Raxol v2.0.1)
View SourceGenServer implementation for event management in Raxol applications.
This server provides a pure functional approach to event management using a PubSub pattern, eliminating Process dictionary usage and implementing proper OTP supervision patterns.
Features
- Event handler registration with module/function callbacks
- PubSub-style subscriptions with filters
- Broadcast and targeted event dispatching
- Supervised state management with fault tolerance
- Support for priority handlers
- Event history tracking (optional)
State Structure
The server maintains state with the following structure:
%{
handlers: %{event_type => [{module, function, priority}]},
subscriptions: %{ref => %{pid: pid, event_types: [], filters: [], monitor_ref: ref}},
monitors: %{monitor_ref => subscription_ref},
event_history: [], # Optional, configurable
config: %{
history_limit: 100,
enable_history: false
}
}Event Dispatching
Events are dispatched in priority order (lower numbers = higher priority). Handlers with the same priority are executed in registration order.
Summary
Functions
Broadcasts an event to all subscribers regardless of filters.
Returns a specification to start this module under a supervisor.
Clears all event handlers.
Clears event history.
Clears all subscriptions.
Dispatches an event to all registered handlers and subscribers.
Dispatches an event synchronously, waiting for all handlers to complete.
Gets event history (if enabled).
Gets all registered event handlers.
Gets the current state (for debugging/testing).
Gets all active subscriptions.
Registers an event handler with optional priority.
Initializes the event manager (for backward compatibility).
Subscribes to events with optional filters.
Subscribes a specific process to events.
Triggers an event with type and payload (compatibility alias).
Unregisters an event handler.
Unsubscribes from events using the subscription reference.
Functions
Broadcasts an event to all subscribers regardless of filters.
Returns a specification to start this module under a supervisor.
See Supervisor.
Clears all event handlers.
Clears event history.
Clears all subscriptions.
Dispatches an event to all registered handlers and subscribers.
This is an asynchronous operation - use dispatch_sync for synchronous dispatch.
Dispatches an event synchronously, waiting for all handlers to complete.
Gets event history (if enabled).
Gets all registered event handlers.
Gets the current state (for debugging/testing).
Gets all active subscriptions.
Registers an event handler with optional priority.
Parameters
event_type- The type of event to handlemodule- The module containing the handler functionfunction- The function to call when the event occursopts- Options including::priority- Handler priority (default: 50, lower = higher priority)
Initializes the event manager (for backward compatibility).
Subscribes to events with optional filters.
Parameters
event_types- List of event types to subscribe toopts- Optional filters and options
Returns
{:ok, ref}- Subscription reference for later unsubscribe
Subscribes a specific process to events.
Triggers an event with type and payload (compatibility alias).
Unregisters an event handler.
Unsubscribes from events using the subscription reference.