T
- the type of the returned resultpublic interface Call<T>
extends java.lang.Cloneable
A Call
object resemebles a future request to execute a method having the following properties:
enqueue(Callback)
method with a Callback
object.execute()
method.isExecuted()
property.Call
instance can be cloned via the clone()
method and executed again.cancel()
method.
It is safe to call cancel()
multiple times.IOException
being thrown or reported via Callback.onFailure(Call, IOException)
.Modifier and Type | Method and Description |
---|---|
void |
cancel()
Cancel this call.
|
Call<T> |
clone() |
void |
enqueue(Callback<T> callback)
Asynchronously send the request and notify
callback of its response or if an error
occurred talking to the server, creating the request, or processing the response. |
T |
enqueueAndWait()
Sends a request on another thread but blocks the calling thread
until the operation is complete or an exception is thrown.
|
T |
enqueueAndWait(long timeout,
java.util.concurrent.TimeUnit timeUnit)
Sends a request on another thread but blocks the calling thread for
at most the amount of time specified in the arguments.
|
T |
execute()
Synchronously send the request and return its response.
|
boolean |
isCancelled() |
boolean |
isExecuted()
|
java.lang.String |
methodName()
The API method name to be executed.
|
java.lang.String methodName()
T execute() throws java.io.IOException
java.io.IOException
- if a problem occurred talking to the server.void enqueue(Callback<T> callback)
callback
of its response or if an error
occurred talking to the server, creating the request, or processing the response.callback
- a non-null object that will be notified when a result is available or an error occurs.java.lang.IllegalArgumentException
- on a null callback
argument.T enqueueAndWait() throws java.io.IOException, java.lang.InterruptedException
java.io.IOException
- on failed IO operationsjava.lang.InterruptedException
- If the waiting thread is interruptedT enqueueAndWait(long timeout, java.util.concurrent.TimeUnit timeUnit) throws java.io.IOException, java.lang.InterruptedException, java.util.concurrent.TimeoutException
Note you are not guaranteed to receive the result after the specified time is up. After the time is up you will receive the result of the request if available or a TimeoutException if the request is not yet completed.
timeout
- The maximum amount of time before an attempt to gather the result of the request.timeUnit
- The units in which you specified the time argument.java.io.IOException
- on failed IO operationsjava.lang.InterruptedException
- if the waiting thread is interruptedjava.util.concurrent.TimeoutException
- if the time is up and the request is not yet completedboolean isExecuted()
true
if this call has been executed, false
otherwisevoid cancel()
boolean isCancelled()
true
if this call has been cancelled, false
otherwise