Class GenericEventBus
java.lang.Object
io.github.astrapi69.design.pattern.eventbus.GenericEventBus
The
GenericEventBus
is a final utility class that provides a centralized event bus
mechanism for managing and dispatching events using EventSource
objects. It maintains a
registry of event sources keyed by strings or class types, enabling efficient event dispatching
and management.-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> void
post
(T source) Posts an event to the event bus.static <T> void
register
(@NonNull io.github.astrapi69.design.pattern.observer.event.EventListener<io.github.astrapi69.design.pattern.observer.event.EventObject<T>> listener, @NonNull Class<T> eventSourceTypeClass) Registers a newEventListener
with the specified event source type class to this EventBus instancestatic <T> void
unregister
(@NonNull io.github.astrapi69.design.pattern.observer.event.EventListener<io.github.astrapi69.design.pattern.observer.event.EventObject<T>> listener, @NonNull Class<T> eventSourceTypeClass) Unregisters the givenEventListener
with the specified event source type class from this EventBus
-
Method Details
-
register
public static <T> void register(@NonNull @NonNull io.github.astrapi69.design.pattern.observer.event.EventListener<io.github.astrapi69.design.pattern.observer.event.EventObject<T>> listener, @NonNull @NonNull Class<T> eventSourceTypeClass) Registers a newEventListener
with the specified event source type class to this EventBus instance- Type Parameters:
T
- the type parameter that represents the event source- Parameters:
listener
- the listener to registereventSourceTypeClass
- the class type of the event source
-
unregister
public static <T> void unregister(@NonNull @NonNull io.github.astrapi69.design.pattern.observer.event.EventListener<io.github.astrapi69.design.pattern.observer.event.EventObject<T>> listener, @NonNull @NonNull Class<T> eventSourceTypeClass) Unregisters the givenEventListener
with the specified event source type class from this EventBus- Type Parameters:
T
- the type parameter that represents the event source- Parameters:
listener
- the listener to registereventSourceTypeClass
- the class type of the event source
-
post
public static <T> void post(@NonNull T source) Posts an event to the event bus. The event is dispatched to all registered listeners associated with the event's class type- Type Parameters:
T
- the type parameter representing the event source- Parameters:
source
- the source event to be posted
-