Class FeatureListenerRegistry

java.lang.Object
ovh.mythmc.gestalt.features.FeatureListenerRegistry

public final class FeatureListenerRegistry extends Object
Manages the registry of listener objects that receive FeatureEvent notifications.

Objects are registered via register(Object) and are notified of feature lifecycle events by call(Class, FeatureEvent). The registry uses FeatureListenerProcessor to resolve which methods on each listener object should be invoked for a given event.

  • Constructor Summary

    Constructors
    Constructor
    Description
    FeatureListenerRegistry(@NotNull Gestalt gestalt)
    Constructs a new FeatureListenerRegistry for the given Gestalt instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    call(@NotNull Class<?> clazz, @NotNull FeatureEvent event)
    Dispatches the given FeatureEvent to all listener objects registered for the specified feature class.
    getInstances(@NotNull Class<?> clazz)
    Returns all registered listener objects that listen to the given feature class.
    getInstances(@NotNull String className)
    Returns all registered listener objects that listen to the feature identified by the given class name.
    boolean
    hasListeners(@NotNull Class<?> clazz)
    Returns whether any listener is registered for the given feature class.
    boolean
    hasListeners(@NotNull String className)
    Returns whether any listener is registered for the feature identified by the given class name.
    boolean
    isRegistered(@NotNull Object instance)
    Returns whether the given object is currently registered as a listener.
    void
    register(@NotNull Object instance)
    Registers a listener object to receive feature lifecycle events.
    void
    register(@NotNull Object instance, boolean callEventWhenRegistered)
    Registers a listener object and optionally immediately dispatches FeatureEvent.ENABLE for all currently enabled features.
    void
    unregister(@NotNull Object instance)
    Unregisters a listener object so it no longer receives feature lifecycle events.
    void
    unregisterAllListeners(@NotNull Class<?> clazz)
    Unregisters all listener objects that are instances of the specified class.
    void
    unregisterAllListeners(@NotNull String className)
    Unregisters all listener objects associated with the specified class name.

    Methods inherited from class java.lang.Object

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

    • FeatureListenerRegistry

      public FeatureListenerRegistry(@NotNull @NotNull Gestalt gestalt)
      Constructs a new FeatureListenerRegistry for the given Gestalt instance.
      Parameters:
      gestalt - the active Gestalt instance
  • Method Details

    • register

      public void register(@NotNull @NotNull Object instance)
      Registers a listener object to receive feature lifecycle events.
      Parameters:
      instance - the listener object to register
    • register

      @Experimental public void register(@NotNull @NotNull Object instance, boolean callEventWhenRegistered)
      Registers a listener object and optionally immediately dispatches FeatureEvent.ENABLE for all currently enabled features.
      Parameters:
      instance - the listener object to register
      callEventWhenRegistered - if true, fires FeatureEvent.ENABLE for every currently enabled feature immediately upon registration
    • unregister

      public void unregister(@NotNull @NotNull Object instance)
      Unregisters a listener object so it no longer receives feature lifecycle events.
      Parameters:
      instance - the listener object to unregister
    • unregisterAllListeners

      public void unregisterAllListeners(@NotNull @NotNull String className)
      Unregisters all listener objects associated with the specified class name.
      Parameters:
      className - the fully qualified name of the listener class to remove
    • unregisterAllListeners

      public void unregisterAllListeners(@NotNull @NotNull Class<?> clazz)
      Unregisters all listener objects that are instances of the specified class.
      Parameters:
      clazz - the listener class whose instances should be removed
    • isRegistered

      public boolean isRegistered(@NotNull @NotNull Object instance)
      Returns whether the given object is currently registered as a listener.
      Parameters:
      instance - the object to check
      Returns:
      true if the object is registered
    • getInstances

      public Set<Object> getInstances(@NotNull @NotNull String className)
      Returns all registered listener objects that listen to the feature identified by the given class name.
      Parameters:
      className - the fully qualified name of the feature class
      Returns:
      a set of listener instances that listen to the specified feature
    • getInstances

      public Set<Object> getInstances(@NotNull @NotNull Class<?> clazz)
      Returns all registered listener objects that listen to the given feature class.
      Parameters:
      clazz - the feature class
      Returns:
      a set of listener instances that listen to the specified feature
    • hasListeners

      public boolean hasListeners(@NotNull @NotNull String className)
      Returns whether any listener is registered for the feature identified by the given class name.
      Parameters:
      className - the fully qualified name of the feature class
      Returns:
      true if at least one listener is registered for the feature
    • hasListeners

      public boolean hasListeners(@NotNull @NotNull Class<?> clazz)
      Returns whether any listener is registered for the given feature class.
      Parameters:
      clazz - the feature class
      Returns:
      true if at least one listener is registered for the feature
    • call

      public void call(@NotNull @NotNull Class<?> clazz, @NotNull @NotNull FeatureEvent event)
      Dispatches the given FeatureEvent to all listener objects registered for the specified feature class.
      Parameters:
      clazz - the feature class that triggered the event
      event - the lifecycle event to dispatch