Package ovh.mythmc.gestalt.features
Class FeatureListenerRegistry
java.lang.Object
ovh.mythmc.gestalt.features.FeatureListenerRegistry
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
ConstructorsConstructorDescriptionFeatureListenerRegistry(@NotNull Gestalt gestalt) Constructs a newFeatureListenerRegistryfor the givenGestaltinstance. -
Method Summary
Modifier and TypeMethodDescriptionvoidcall(@NotNull Class<?> clazz, @NotNull FeatureEvent event) Dispatches the givenFeatureEventto 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.booleanhasListeners(@NotNull Class<?> clazz) Returns whether any listener is registered for the given feature class.booleanhasListeners(@NotNull String className) Returns whether any listener is registered for the feature identified by the given class name.booleanisRegistered(@NotNull Object instance) Returns whether the given object is currently registered as a listener.voidRegisters a listener object to receive feature lifecycle events.voidRegisters a listener object and optionally immediately dispatchesFeatureEvent.ENABLEfor all currently enabled features.voidunregister(@NotNull Object instance) Unregisters a listener object so it no longer receives feature lifecycle events.voidunregisterAllListeners(@NotNull Class<?> clazz) Unregisters all listener objects that are instances of the specified class.voidunregisterAllListeners(@NotNull String className) Unregisters all listener objects associated with the specified class name.
-
Constructor Details
-
FeatureListenerRegistry
Constructs a newFeatureListenerRegistryfor the givenGestaltinstance.- Parameters:
gestalt- the active Gestalt instance
-
-
Method Details
-
register
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 dispatchesFeatureEvent.ENABLEfor all currently enabled features.- Parameters:
instance- the listener object to registercallEventWhenRegistered- iftrue, firesFeatureEvent.ENABLEfor every currently enabled feature immediately upon registration
-
unregister
Unregisters a listener object so it no longer receives feature lifecycle events.- Parameters:
instance- the listener object to unregister
-
unregisterAllListeners
Unregisters all listener objects associated with the specified class name.- Parameters:
className- the fully qualified name of the listener class to remove
-
unregisterAllListeners
Unregisters all listener objects that are instances of the specified class.- Parameters:
clazz- the listener class whose instances should be removed
-
isRegistered
Returns whether the given object is currently registered as a listener.- Parameters:
instance- the object to check- Returns:
trueif the object is registered
-
getInstances
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
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
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:
trueif at least one listener is registered for the feature
-
hasListeners
Returns whether any listener is registered for the given feature class.- Parameters:
clazz- the feature class- Returns:
trueif at least one listener is registered for the feature
-
call
Dispatches the givenFeatureEventto all listener objects registered for the specified feature class.- Parameters:
clazz- the feature class that triggered the eventevent- the lifecycle event to dispatch
-