T
- The generic response type for this RestActionpublic abstract class RestAction<T>
extends java.lang.Object
Methods that return an instance of RestAction require an additional step to complete the execution. Thus the user needs to append a follow-up method.
A default RestAction is issued with the following operations:
queue()
, queue(Consumer)
, queue(Consumer, Consumer)
submit()
, submit(boolean)
complete()
, complete(boolean)
submit()
.
queue()
operations.
Modifier and Type | Class and Description |
---|---|
static class |
RestAction.EmptyRestAction<T>
Specialized form of
RestAction that is used to provide information that
has already been retrieved or generated so that another request does not need to be made to Discord. |
Modifier and Type | Field and Description |
---|---|
static java.util.function.Consumer<java.lang.Throwable> |
DEFAULT_FAILURE |
static java.util.function.Consumer |
DEFAULT_SUCCESS |
static SimpleLog |
LOG |
Constructor and Description |
---|
RestAction(JDA api,
Route.CompiledRoute route,
java.lang.Object data)
Creates a new RestAction instance
|
Modifier and Type | Method and Description |
---|---|
T |
block()
Deprecated.
use
complete(boolean) instead! |
T |
complete()
Blocks the current Thread and awaits the completion
of an
submit() request. |
T |
complete(boolean shouldQueue)
Blocks the current Thread and awaits the completion
of an
submit() request. |
JDA |
getJDA()
The current JDA instance
|
void |
queue()
Submits a Request for execution.
|
void |
queue(java.util.function.Consumer<T> success)
Submits a Request for execution.
|
void |
queue(java.util.function.Consumer<T> success,
java.util.function.Consumer<java.lang.Throwable> failure)
Submits a Request for execution.
|
java.util.concurrent.Future<T> |
submit()
Submits a Request for execution and provides
an
Future representing
its completion task. |
java.util.concurrent.Future<T> |
submit(boolean shouldQueue)
Submits a Request for execution and provides
an
Future representing
its completion task. |
public static final SimpleLog LOG
public static java.util.function.Consumer DEFAULT_SUCCESS
public static java.util.function.Consumer<java.lang.Throwable> DEFAULT_FAILURE
public RestAction(JDA api, Route.CompiledRoute route, java.lang.Object data)
api
- The current JDA instanceroute
- The Route.CompiledRoute
to be used for rate limit handlingdata
- The data that should be sent to the specified route. (can be null)public JDA getJDA()
public void queue()
DEFAULT_SUCCESS
and
DEFAULT_FAILURE
This method is asynchronous
public void queue(java.util.function.Consumer<T> success)
This method is asynchronous
success
- The success callback that will be called at a convenient time
for the API. (can be null)public void queue(java.util.function.Consumer<T> success, java.util.function.Consumer<java.lang.Throwable> failure)
This method is asynchronous
success
- The success callback that will be called at a convenient time
for the API. (can be null)failure
- The failure callback that will be called if the Request
encounters an exception at its execution point.public java.util.concurrent.Future<T> submit()
Future
representing
its completion task.
Future
task representing the completion promisepublic java.util.concurrent.Future<T> submit(boolean shouldQueue)
Future
representing
its completion task.
shouldQueue
- Whether the Request should automatically handle rate limitations. (default true)Future
task representing the completion promisepublic T complete()
submit()
request.
This might throw RuntimeExceptions
public T complete(boolean shouldQueue) throws RateLimitedException
submit()
request.
shouldQueue
- Whether this should automatically handle rate limitations (default true)RateLimitedException
- If we were rate limited and the shouldQueue
is false
complete()
to avoid this Exception.@Deprecated public T block() throws RateLimitedException
complete(boolean)
instead!RateLimitedException
- If the request was ratelimited.