Package org.javacord.core.util.event
Class EventDispatcherBase
- java.lang.Object
-
- org.javacord.core.util.event.EventDispatcherBase
-
- Direct Known Subclasses:
EventDispatcher
public abstract class EventDispatcherBase extends Object
This class is the base for the class used to dispatch events.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
EventDispatcherBase(DiscordApiImpl api)
Creates a new event dispatcher.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <T> void
dispatchEvent(DispatchQueueSelector queueSelector, List<T> listeners, Consumer<T> consumer)
Dispatches an event to the given listeners using the provided consumer.protected DiscordApiImpl
getApi()
Gets the discord api instance.void
setExecutionTimeCheckingEnabled(boolean enable)
Sets whether execution time checking should be enabled or not.
-
-
-
Constructor Detail
-
EventDispatcherBase
protected EventDispatcherBase(DiscordApiImpl api)
Creates a new event dispatcher.- Parameters:
api
- The discord api instance.
-
-
Method Detail
-
getApi
protected DiscordApiImpl getApi()
Gets the discord api instance.- Returns:
- The discord api instance.
-
setExecutionTimeCheckingEnabled
public void setExecutionTimeCheckingEnabled(boolean enable)
Sets whether execution time checking should be enabled or not.- Parameters:
enable
- Whether execution time checking should be enabled or not.
-
dispatchEvent
protected <T> void dispatchEvent(DispatchQueueSelector queueSelector, List<T> listeners, Consumer<T> consumer)
Dispatches an event to the given listeners using the provided consumer. Calling this method usually looks like this:dispatchEvent(server, listeners, listener -> listener.onXyz(event));
- Type Parameters:
T
- The type of the listener.- Parameters:
queueSelector
- The object which is used to determine in which queue the event should be dispatched. Usually the object is a server object (for server-dependent events), a discord api instance (for server-independent events, like DMs or GMs) ornull
(for lifecycle events, like connection lost, resume or reconnect). Providingnull
means, that already started dispatchings are going to be finished, then all events with anull
queue selector are dispatched and finally other events are dispatched like normal again. Events with the same queue selector are dispatched sequentially in the correct order of enqueueal, but on arbitrary threads from a thread pool. Events with different queue selectors are dispatched in parallel.listeners
- A list with listeners which get consumed by the given consumer.consumer
- A consumer which consumes all listeners from the given list and is meant to call theironXyz(Event)
method.
-
-