Class EventEmitter

java.lang.Object
org.omegazero.common.event.EventEmitter

public class EventEmitter extends Object
Used for distributing and executing events among a set of registered listeners.

Listeners are added to a specific event name using addEventListener(String, GenericRunnable) or similar methods. Upon dispatching an event using runEvent(String, Object...), all event listeners registered for the given event name are called with the given arguments. The number of arguments passed and the number of arguments in the event listeners must match, otherwise an IllegalArgumentException will be thrown at the listener-level.

Each event may also have a default listener registered, which is called when the event is emitted, and only if no other (regular) listeners are registered (see setDefaultEventListener(String, GenericRunnable)).

By default, all event listeners are executed regardless of any exceptions thrown at the listener-level. If any listener did throw an exception, the runEvent call will throw an ExecutionFailedException detailing the thrown exception(s), after all listeners were executed. See also: setCoalesceListenerErrors(boolean).

A call to createEventId(String, int) will switch this EventEmitter to fastAccess mode, which may be used for more efficient event dispatching. In this mode, all event names must be registered with a call to this method.

This class is thread-safe.

Since:
2.10
API Note:
The behavior and API naming of this class is heavily inspired by the similar Node.js events API