public class AsyncRequest extends Request implements java.lang.Runnable
RiotApiAsync
object.RiotApiAsync
CODE_ERROR_BAD_GATEWAY, CODE_ERROR_BAD_REQUEST, CODE_ERROR_FORBIDDEN, CODE_ERROR_GATEWAY_TIMEOUT, CODE_ERROR_METHOD_NOT_ALLOWED, CODE_ERROR_NOT_FOUND, CODE_ERROR_RATE_LIMITED, CODE_ERROR_SERVER_ERROR, CODE_ERROR_SERVICE_UNAVAILABLE, CODE_ERROR_UNAUTHORIZED, CODE_ERROR_UNPROCESSABLE_ENTITY, CODE_ERROR_UNSUPPORTED_MEDIA_TYPE, CODE_SUCCESS_NO_CONTENT, CODE_SUCCESS_OK
Constructor and Description |
---|
AsyncRequest(ApiConfig config,
ApiMethod object)
Constructs an asynchronous request
|
Modifier and Type | Method and Description |
---|---|
void |
addListeners(RequestListener... listeners)
Adds one or more
RequestListener to this request |
void |
await()
Waits indefinitely until the request completes.
|
void |
await(long timeout,
java.util.concurrent.TimeUnit unit)
Waits for at most the given time until the request completes.
|
void |
await(long timeout,
java.util.concurrent.TimeUnit unit,
boolean cancelOnTimeout)
Waits for at most the given time until the request completes.
|
boolean |
cancel()
Attempts to cancel the request.
|
void |
execute()
Executes the request
|
<T> T |
getDto()
Retrieves the request's result.
|
<T> T |
getDtoAndThrowException()
Retrieves the request's result.
|
boolean |
isSent()
Returns
true if this request has started execution |
void |
removeAllListeners()
Removes all
RequestListener from this request |
void |
removeListener(RequestListener listeners)
Removes one or more
RequestListener from this request |
void |
run() |
getException, getObject, getResponse, isCancelled, isDone, isFailed, isPending, isSuccessful, isTimeOut
public void addListeners(RequestListener... listeners)
RequestListener
to this requestlisteners
- One or more request listenersRequestListener
public void await() throws java.lang.InterruptedException
If the thread is interrupted while waiting for the request to complete, this method will throw an InterruptedException
and
the thread's interrupt flag will be cleared.
Please note that this method is blocking and thus negates the advantage of the asynchronous nature of this class. Consider using a
RequestListener
instead.
java.lang.InterruptedException
- If the method is interrupted by calling Thread.interrupt()
. The interrupt flag will be clearedpublic void await(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.TimeoutException
If the thread is interrupted while waiting for the request to complete, this method will throw an InterruptedException
and
the thread's interrupt flag will be cleared.
Please note that this method is blocking and thus negates the advantage of the asynchronous nature of this class. Consider using a
RequestListener
instead.
timeout
- The maximum amount of the given time unit to waitunit
- The time unit of the timeout
argumentjava.lang.InterruptedException
- If the method is interrupted by calling Thread.interrupt()
. The interrupt flag will be clearedjava.util.concurrent.TimeoutException
- If the given time elapsed without the request completingpublic void await(long timeout, java.util.concurrent.TimeUnit unit, boolean cancelOnTimeout) throws java.lang.InterruptedException, java.util.concurrent.TimeoutException
If the thread is interrupted while waiting for the request to complete, this method will throw an InterruptedException
and
the thread's interrupt flag will be cleared.
Please note that this method is blocking and thus negates the advantage of the asynchronous nature of this class. Consider using a
RequestListener
instead.
timeout
- The maximum amount of the given time unit to waitunit
- The time unit of the timeout
argumentcancelOnTimeout
- Whether or not the request should be cancelled, if the given timeout
is elapsed without the request completingjava.lang.InterruptedException
- If the method is interrupted by calling Thread.interrupt()
. The interrupt flag will be clearedjava.util.concurrent.TimeoutException
- If the given time elapsed without the request completingpublic boolean cancel()
Request
cancel
is called, this request should never run.public void execute()
Request
public <T> T getDto()
If you want this method to throw exceptions, please use getDtoAndThrowException()
instead.
public <T> T getDtoAndThrowException() throws RiotApiException
If you do not want this method to throw exceptions, please use getDto()
instead.
null
if the request did not finish yetRiotApiException
- If an exception occurs while parsing the Riot Api's responsepublic boolean isSent()
true
if this request has started executiontrue
if this request has started executionpublic void removeAllListeners()
RequestListener
from this requestRequestListener
public void removeListener(RequestListener listeners)
RequestListener
from this requestlistener
- One or more listeners to removeRequestListener
public void run()
run
in interface java.lang.Runnable