com.android.volley.toolbox
Class RequestFuture<T>

java.lang.Object
  extended by com.android.volley.toolbox.RequestFuture<T>
Type Parameters:
T - The type of parsed response this future expects.
All Implemented Interfaces:
Response.ErrorListener, Response.Listener<T>, Future<T>

public class RequestFuture<T>
extends Object
implements Future<T>, Response.Listener<T>, Response.ErrorListener

A Future that represents a Volley request. Used by providing as your response and error listeners. For example:

 RequestFuture<JSONObject> future = RequestFuture.newFuture();
 MyRequest request = new MyRequest(URL, future, future);

 // If you want to be able to cancel the request:
 future.setRequest(requestQueue.add(request));

 // Otherwise:
 requestQueue.add(request);

 try {
   JSONObject response = future.get();
   // do something with response
 } catch (InterruptedException e) {
   // handle the error
 } catch (ExecutionException e) {
   // handle the error
 }
 


Method Summary
 boolean cancel(boolean mayInterruptIfRunning)
           
 T get()
           
 T get(long timeout, TimeUnit unit)
           
 boolean isCancelled()
           
 boolean isDone()
           
static
<E> RequestFuture<E>
newFuture()
           
 void onErrorResponse(VolleyError error)
          Callback method that an error has been occurred with the provided error code and optional user-readable message.
 void onResponse(T response)
          Called when a response is received.
 void setRequest(Request<?> request)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newFuture

public static <E> RequestFuture<E> newFuture()

setRequest

public void setRequest(Request<?> request)

cancel

public boolean cancel(boolean mayInterruptIfRunning)
Specified by:
cancel in interface Future<T>

get

public T get()
      throws InterruptedException,
             ExecutionException
Specified by:
get in interface Future<T>
Throws:
InterruptedException
ExecutionException

get

public T get(long timeout,
             TimeUnit unit)
      throws InterruptedException,
             ExecutionException,
             TimeoutException
Specified by:
get in interface Future<T>
Throws:
InterruptedException
ExecutionException
TimeoutException

isCancelled

public boolean isCancelled()
Specified by:
isCancelled in interface Future<T>

isDone

public boolean isDone()
Specified by:
isDone in interface Future<T>

onResponse

public void onResponse(T response)
Description copied from interface: Response.Listener
Called when a response is received.

Specified by:
onResponse in interface Response.Listener<T>

onErrorResponse

public void onErrorResponse(VolleyError error)
Description copied from interface: Response.ErrorListener
Callback method that an error has been occurred with the provided error code and optional user-readable message.

Specified by:
onErrorResponse in interface Response.ErrorListener