Package com.j3d.engine.react.events
Events
The engine, in most cases instead of trying to finder a specific class instance and method to call, makes use of "events" which allow any parts of the engine to fire events to any other part at any time of execution.
This is not an event bus type of event stuff. The listener has to know and attach itself to the instance of the class it will listen to events from.
Any class which extends EventEmitter inherits event emitting
capabilities to any class which it attaches that implements EventListener.
Classes which cannot directly extends EventEmitter can instead implement EventEmitterInterface
and hence use the generic static utilities provided by EventEmitter
such as to still emit events.
An event is broadcast with an EventPayload to all attached listeners.
This class can also be the superclass of concrete implementations, and it's up to the listener to
decipher the payload. However, there is also a EventType enum
where all event types can be categorised by a single enum before performing type casting.
Classes and interfaces
-
An
EventEmitteris a class that allows other classes to register as listeners and receive events.The
EventEmitterInterfaceis an interface that allows classes that cannot extendEventEmitterto still emit events using its static utility methods. -
An
EventListeneris an interface which defines any class as one that can listen for events and handle said events viaEventListener.onEvent(com.j3d.engine.react.events.EventType, com.j3d.engine.react.events.EventPayload)An
EventReactoris a special type ofEventListenerwhich is removed after it has received it's event. It "reacts" to the event once and is removed thereafter.An
IdempotentEventListeneris a special type ofEventListenerthat guarantees that processing the same event multiple times will produce the same result as processing it once. This is useful for events that might be re-triggered or re-broadcast, ensuring consistent state. -
An
EventPayloadis a class that carries data related to an event. It can be extended to provide specific event data. -
An
EventTypeis an enum that categorises different types of events, allowing listeners to filter and handle specific event types. -
An
EventEmitterAndListeneris a class which other classes can extend which itself extendsEventEmitterand implementsEventListenerfor both capabilities -
EventEmitterAndListenerInterfaceis the previous, but interface version for classes which cant extendEventEmitterAndListenerdirectly -
CapableEventListeneris a specialisation of anEventListenerwhich is capable of returning a value viaCapableEventListener.capableOnEvent(EventType, EventPayload)and only able to be listened/further returned byCapableEventEmitter.capableBroadcast(EventType, EventPayload) -
CapableEventEmitteris a specialisation of anEventEmitterwhich simply addsCapableEventEmitter.capableBroadcast(EventType, EventPayload)which if the return type that the implementor registers it to listen for is returned by anyCapableEventListener, it returns it. (It can also normally listen to other events if no capable event listener is present)
- Author:
- Lehlogonolo Poole
-
ClassDescriptionWhat makes this different from your generic
EventEmitteris that, this has runtime support forCapableEventListener, which returns a value.A specialization of anEventListenerthat is capable of returning a value when handling an event.EventEmitter is a class that allows for other classes to attach events that they can broadcast to at any time.Abstract class which gives an extender event emitting capabilities and listening capabilities.Interface which gives an extender event emitting capabilities and listening capabilities.EventEmitterInterface is an interface that allows for other classes to attach events that they can broadcast to at any time.EventListener is an interface which just allows Objects to listen for incoming Events at any time.EventPayload<T>EventPayload is an abstract class which is used to represent the properties that the called event may input and or return.An interface which only reacts to a single event and later gets removed.Events is an enum that describes the possible Events that a listener can listen for.IdempotentEventListener<T extends EventPayload<?>, V>A simple interface for implementors to use such that they dont bloat some specific setting due to multiple events firing that do the same thing.