Package com.avrix.events
Class EventManager
java.lang.Object
com.avrix.events.EventManager
Manages
Event
subscriptions and their raising.
Allows objects to register themselves as listeners for specific events and raise those events dynamically.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final record
Standard event listener class -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addListener
(Event listener) Registers a listener object for a specific event.static void
addListener
(Event listener, Priority priority) Registers a listener object for a specific event.static void
Clears all registered event listeners.static void
clearListenersForEvent
(String eventName) Clears all registered event listeners for a specific event.static Map<String,
List<EventManager.EventListener>> Returns a copy of all registered listeners for all events.static List<EventManager.EventListener>
getListenersForEvent
(String eventName) Returns aList
of listeners for the specified event.static void
invokeEvent
(String eventName, Object... args) Raises an event by its name, passing arguments to listeners registered for that event.
-
Constructor Details
-
EventManager
public EventManager()
-
-
Method Details
-
getAllListeners
Returns a copy of all registered listeners for all events. -
getListenersForEvent
Returns aList
of listeners for the specified event. -
clearAllListeners
public static void clearAllListeners()Clears all registered event listeners. -
clearListenersForEvent
Clears all registered event listeners for a specific event.- Parameters:
eventName
- The name of the event to clear listeners for.
-
addListener
Registers a listener object for a specific event. -
addListener
Registers a listener object for a specific event. Handler priority is set to NORMAL- Parameters:
listener
-Event
listener. Must have a handleEvent method with a signature corresponding to the event.
-
invokeEvent
Raises an event by its name, passing arguments to listeners registered for that event. The method dynamically looks up and calls the handleEvent method on each event listener, passing the specified arguments. If an error occurs during a call, it is logged and the process continues for the remaining listeners.- Parameters:
eventName
- The name of the event to raise. The event name is case insensitive.args
- Arguments to be passed to the event listener's handleEvent method. The type and number of arguments must match the expected parameters of the handleEvent method.
-