Class DeferredRestAction<T,R extends RestAction<T>>
- All Implemented Interfaces:
RestAction<T>
,AuditableRestAction<T>
,CacheRestAction<T>
-
Field Summary
Fields inherited from interface net.dv8tion.jda.api.requests.restaction.AuditableRestAction
MAX_REASON_LENGTH
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncomplete
(boolean shouldQueue) Blocks the current Thread and awaits the completion of anRestAction.submit()
request.deadline
(long timestamp) Similar toRestAction.timeout(long, TimeUnit)
but schedules a deadline at which the request has to be completed.getCheck()
The current checks for this RestAction.getJDA()
The current JDA instancevoid
Submits a Request for execution.Applies the specified reason as audit-log reason field.setCacheCheck
(BooleanSupplier checks) setCheck
(BooleanSupplier checks) Sets the last-second checks before finally executing the http request in the queue.submit
(boolean shouldQueue) Submits a Request for execution and provides aCompletableFuture
representing its completion task.Timeout for this RestAction instance.useCache
(boolean useCache) Sets whether this request should rely on cached entities, or always retrieve a new one.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.dv8tion.jda.api.requests.restaction.CacheRestAction
addCheck
Methods inherited from interface net.dv8tion.jda.api.requests.RestAction
and, and, complete, completeAfter, delay, delay, delay, delay, flatMap, flatMap, map, mapToResult, onErrorFlatMap, onErrorFlatMap, onErrorMap, onErrorMap, onSuccess, queue, queue, queueAfter, queueAfter, queueAfter, queueAfter, queueAfter, queueAfter, submit, submitAfter, submitAfter, zip
-
Constructor Details
-
DeferredRestAction
-
DeferredRestAction
-
-
Method Details
-
getJDA
Description copied from interface:RestAction
The current JDA instance- Specified by:
getJDA
in interfaceRestAction<T>
- Returns:
- The corresponding JDA instance
-
reason
Description copied from interface:AuditableRestAction
Applies the specified reason as audit-log reason field.
When the provided reason is empty ornull
it will be treated as not set. If the provided reason is longer than 512<T> characters, it will be truncated to fit the limit.Reasons for any AuditableRestAction may be retrieved via
AuditLogEntry.getReason()
in iterableAuditLogPaginationActions
fromGuild.retrieveAuditLogs()
! Forguild bans
, this is also accessible viaGuild.Ban.getReason()
.This will specify the reason via the
X-Audit-Log-Reason
Request Header.- Specified by:
reason
in interfaceAuditableRestAction<T>
- Parameters:
reason
- The reason for this action which should be logged in the Guild's AuditLogs (up to 512<T> characters)- Returns:
- The current AuditableRestAction instance for chaining convenience
- See Also:
-
setCheck
Description copied from interface:AuditableRestAction
Sets the last-second checks before finally executing the http request in the queue.
If the provided supplier evaluates tofalse
or throws an exception this will not be finished. When an exception is thrown from the supplier it will be provided to the failure callback.- Specified by:
setCheck
in interfaceAuditableRestAction<T>
- Specified by:
setCheck
in interfaceCacheRestAction<T>
- Specified by:
setCheck
in interfaceRestAction<T>
- Parameters:
checks
- The checks to run before executing the request, ornull
to run no checks- Returns:
- The current RestAction for chaining convenience
- See Also:
-
getCheck
Description copied from interface:RestAction
The current checks for this RestAction.- Specified by:
getCheck
in interfaceRestAction<T>
- Returns:
- The current checks, or null if none were set
- See Also:
-
timeout
Description copied from interface:AuditableRestAction
Timeout for this RestAction instance.
If the request doesn't get executed within the timeout it will fail.When a RestAction times out, it will fail with a
TimeoutException
. This is the same asdeadline(System.currentTimeMillis() + unit.toMillis(timeout))
.Example
action.timeout(10, TimeUnit.SECONDS) // 10 seconds from now .queueAfter(20, SECONDS); // request will not be executed within deadline and timeout immediately after 20 seconds
- Specified by:
timeout
in interfaceAuditableRestAction<T>
- Specified by:
timeout
in interfaceCacheRestAction<T>
- Specified by:
timeout
in interfaceRestAction<T>
- Parameters:
timeout
- The timeout to useunit
-Unit
for the timeout value- Returns:
- The same RestAction instance with the applied timeout
- See Also:
-
deadline
Description copied from interface:AuditableRestAction
Similar toRestAction.timeout(long, TimeUnit)
but schedules a deadline at which the request has to be completed.
If the deadline is reached, the request will fail with aTimeoutException
.This does not mean that the request will immediately timeout when the deadline is reached. JDA will check the deadline right before executing the request or within intervals in a worker thread. This only means the request will timeout if the deadline has passed.
Example
action.deadline(System.currentTimeMillis() + 10000) // 10 seconds from now .queueAfter(20, SECONDS); // request will not be executed within deadline and timeout immediately after 20 seconds
- Specified by:
deadline
in interfaceAuditableRestAction<T>
- Specified by:
deadline
in interfaceCacheRestAction<T>
- Specified by:
deadline
in interfaceRestAction<T>
- Parameters:
timestamp
- Millisecond timestamp at which the request will timeout- Returns:
- The same RestAction with the applied deadline
- See Also:
-
useCache
Description copied from interface:CacheRestAction
Sets whether this request should rely on cached entities, or always retrieve a new one.- Specified by:
useCache
in interfaceCacheRestAction<T>
- Parameters:
useCache
- True if the cache should be used when available, even if the entity might be outdated. False, to always request a new instance from the API.- Returns:
- This RestAction instance
-
setCacheCheck
-
queue
Description copied from interface:RestAction
Submits a Request for execution.This method is asynchronous
Example
public static void sendPrivateMessage(JDA jda, String userId, String content) { // Retrieve the user by their id RestAction<User> action = jda.retrieveUserById(userId); action.queue( // Handle success if the user exists (user) -> user.openPrivateChannel().queue( (channel) -> channel.sendMessage(content).queue()), // Handle failure if the user does not exist (or another issue appeared) (error) -> error.printStackTrace() ); // Alternatively use submit() to remove nested callbacks }
- Specified by:
queue
in interfaceRestAction<T>
- Parameters:
success
- The success callback that will be called at a convenient time for the API. (can be null to use default)failure
- The failure callback that will be called if the Request encounters an exception at its execution point. (can be null to use default)- See Also:
-
submit
Description copied from interface:RestAction
Submits a Request for execution and provides aCompletableFuture
representing its completion task.
Cancelling the returned Future will result in the cancellation of the Request!- Specified by:
submit
in interfaceRestAction<T>
- Parameters:
shouldQueue
- Whether the Request should automatically handle rate limitations. (default true)- Returns:
- Never-null
CompletableFuture
task representing the completion promise
-
complete
Description copied from interface:RestAction
Blocks the current Thread and awaits the completion of anRestAction.submit()
request.
Used for synchronous logic.- Specified by:
complete
in interfaceRestAction<T>
- Parameters:
shouldQueue
- Whether this should automatically handle rate limitations (default true)- Returns:
- The response value
- Throws:
RateLimitedException
- If we were rate limited and theshouldQueue
is false. UseRestAction.complete()
to avoid this Exception.
-