Class DefaultEventManager
- All Implemented Interfaces:
EventManager
- Since:
- 4.0
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T extends Event>
TCalls the given event to the given channel, only triggering the event listeners which are specifically listening to the given channel unless the channel is *.protected @NonNull EventManagerregisterListener(@NonNull InjectionLayer<?> layer, @NonNull Object listener) Registers all methods in the given listener class which are annotated withEventListenerand are taking only one argument with a subtype ofEvent.registerListener(@NonNull Class<?> listenerClass) Registers all methods in the given listener class which are annotated withEventListenerand are taking only one argument with a subtype ofEvent.registerListener(@NonNull Object listener) Registers all methods in the given listener class which are annotated withEventListenerand are taking only one argument with a subtype ofEvent.protected voidsafeRemove(@NonNull Predicate<RegisteredEventListener> predicate) Safely removes the all registered event listeners which are matching the given predicate.unregisterListener(Object @NonNull ... listeners) Unregisters all listeners which were registered in each of the given listener classes.unregisterListeners(@NonNull ClassLoader classLoader) Unregisters all listeners in classes which were loaded by the given class loader.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface eu.cloudnetservice.driver.event.EventManager
callEvent, registerListeners
-
Field Details
-
bakeLock
-
listeners
-
-
Constructor Details
-
DefaultEventManager
public DefaultEventManager()
-
-
Method Details
-
unregisterListeners
@NonNull public @NonNull EventManager unregisterListeners(@NonNull @NonNull ClassLoader classLoader) Unregisters all listeners in classes which were loaded by the given class loader.- Specified by:
unregisterListenersin interfaceEventManager- Parameters:
classLoader- the loader based onm which to unregister listeners.- Returns:
- the same event manager as used to call the method, for chaining.
-
unregisterListener
Unregisters all listeners which were registered in each of the given listener classes.- Specified by:
unregisterListenerin interfaceEventManager- Parameters:
listeners- the classes to unregister all listeners of.- Returns:
- the same event manager as used to call the method, for chaining.
-
callEvent
Calls the given event to the given channel, only triggering the event listeners which are specifically listening to the given channel unless the channel is *.- Specified by:
callEventin interfaceEventManager- Type Parameters:
T- the type of the event.- Parameters:
channel- the specific channel to call the listeners on.event- the event to call.- Returns:
- the same event as used to call the method, after processing.
-
registerListener
Registers all methods in the given listener class which are annotated withEventListenerand are taking only one argument with a subtype ofEvent. The instance the constructed event listeners are bound to are created by requesting it from the default external injection layer.This method accepts public, protected, default (package) access, and private methods but will not include inherited methods at all.
All methods which are not annotated with
EventListener, are static and are not taking one or more arguments are silently ignored.- Specified by:
registerListenerin interfaceEventManager- Parameters:
listenerClass- the class to create an instance of and register all listeners in.- Returns:
- the same event manager as used to call the method, for chaining.
-
registerListener
Registers all methods in the given listener class which are annotated withEventListenerand are taking only one argument with a subtype ofEvent.This method accepts public, protected, default (package) access, and private methods but will not include inherited methods at all.
All methods which are not annotated with
EventListener, are static and are not taking one or more arguments are silently ignored.- Specified by:
registerListenerin interfaceEventManager- Parameters:
listener- the instance of the listener to register the methods in.- Returns:
- the same event manager as used to call the method, for chaining.
-
registerListener
@NonNull protected @NonNull EventManager registerListener(@NonNull @NonNull InjectionLayer<?> layer, @NonNull @NonNull Object listener) Registers all methods in the given listener class which are annotated withEventListenerand are taking only one argument with a subtype ofEvent.This method accepts public, protected, default (package) access, and private methods but will not include inherited methods at all.
All methods which are not annotated with
EventListener, are static and are not taking one or more arguments are silently ignored.- Parameters:
layer- the injection layer to use to get instances needed for event listeners.listener- the instance of the listener to register the methods in.- Returns:
- the same event manager as used to call the method, for chaining.
- Throws:
NullPointerException- if the given listener or injection layer is null.IllegalArgumentException- if an event listener target doesn't take an event as it's first argument.
-
safeRemove
Safely removes the all registered event listeners which are matching the given predicate.- Parameters:
predicate- the predicate all listeners to remove must match.- Throws:
NullPointerException- if the given predicate is null.
-