java.lang.Object
io.github.astrapi69.design.pattern.eventbus.BaseEventBus

public final class BaseEventBus extends Object
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.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Instantiates a new BaseEventBus object
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> void
    post(T source)
    Posts an event to the event bus.
    <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 new EventListener with the specified event source type class to this EventBus instance
    <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 given EventListener with the specified event source type class from this EventBus

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BaseEventBus

      public BaseEventBus(String name)
      Instantiates a new BaseEventBus object
      Parameters:
      name - the name of this event bus
  • Method Details

    • register

      public <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 new EventListener 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 register
      eventSourceTypeClass - the class type of the event source
    • unregister

      public <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 given EventListener 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 register
      eventSourceTypeClass - the class type of the event source
    • post

      public <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