Package net.dv8tion.jda.api.utils
Class Once.Builder<E extends GenericEvent>
java.lang.Object
net.dv8tion.jda.api.utils.Once.Builder<E>
- Type Parameters:
E
- Type of the event listened to
- Enclosing class:
Once<E extends GenericEvent>
Builds a one-time event listener, can be reused.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAdds an event filter, all filters need to returntrue
for the event to be consumed.setTimeoutPool
(ScheduledExecutorService timeoutPool) Sets the thread pool used to schedule timeouts and run its callback.Starts listening for the event, once.Sets the timeout duration, after which the event is no longer listener for.Sets the timeout duration, after which the event is no longer listener for, and the callback is run.
-
Constructor Details
-
Builder
Creates a builder for a one-time event listener- Parameters:
jda
- The JDA instanceeventType
- The event type to listen for- Throws:
IllegalArgumentException
- If any of the parameters is null
-
-
Method Details
-
filter
Adds an event filter, all filters need to returntrue
for the event to be consumed.If the filter throws an exception, this listener will unregister itself.
- Parameters:
filter
- The filter to add, returnstrue
if the event can be consumed- Returns:
- This instance for chaining convenience
- Throws:
IllegalArgumentException
- If the filter is null
-
timeout
Sets the timeout duration, after which the event is no longer listener for.- Parameters:
timeout
- The duration after which the event is no longer listener for- Returns:
- This instance for chaining convenience
- Throws:
IllegalArgumentException
- If the timeout is null
-
timeout
@Nonnull public Once.Builder<E> timeout(@Nonnull Duration timeout, @Nullable Runnable timeoutCallback) Sets the timeout duration, after which the event is no longer listener for, and the callback is run.- Parameters:
timeout
- The duration after which the event is no longer listener fortimeoutCallback
- The callback run after the duration- Returns:
- This instance for chaining convenience
- Throws:
IllegalArgumentException
- If the timeout is null
-
setTimeoutPool
Sets the thread pool used to schedule timeouts and run its callback.By default
JDA.getGatewayPool()
is used.- Parameters:
timeoutPool
- The thread pool to use for timeouts- Returns:
- This instance for chaining convenience
- Throws:
IllegalArgumentException
- If the timeout pool is null
-
subscribe
Starts listening for the event, once.The task will be completed after all
filters
returntrue
.Exceptions thrown in
blocking
andasync
contexts includes:CancellationException
- WhenTask.cancel()
is calledTimeoutException
- When the listener has expired- Any exception thrown by the
timeout callback
- Returns:
Task
returning an event satisfying all preconditions- Throws:
IllegalArgumentException
- If the callback is null- See Also:
-