FileDocCategorySizeDatePackage
RequestFuture.javaAPI DocAndroid 5.1 API4083Thu Mar 12 22:22:56 GMT 2015com.android.volley.toolbox

RequestFuture

public class RequestFuture extends Object implements Response.ErrorListener, Future, Response.Listener
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
}
param
The type of parsed response this future expects.

Fields Summary
private com.android.volley.Request
mRequest
private boolean
mResultReceived
private T
mResult
private com.android.volley.VolleyError
mException
Constructors Summary
private RequestFuture()

Methods Summary
public synchronized booleancancel(boolean mayInterruptIfRunning)

        if (mRequest == null) {
            return false;
        }

        if (!isDone()) {
            mRequest.cancel();
            return true;
        } else {
            return false;
        }
    
private synchronized TdoGet(java.lang.Long timeoutMs)

        if (mException != null) {
            throw new ExecutionException(mException);
        }

        if (mResultReceived) {
            return mResult;
        }

        if (timeoutMs == null) {
            wait(0);
        } else if (timeoutMs > 0) {
            wait(timeoutMs);
        }

        if (mException != null) {
            throw new ExecutionException(mException);
        }

        if (!mResultReceived) {
            throw new TimeoutException();
        }

        return mResult;
    
public Tget()

        try {
            return doGet(null);
        } catch (TimeoutException e) {
            throw new AssertionError(e);
        }
    
public Tget(long timeout, java.util.concurrent.TimeUnit unit)

        return doGet(TimeUnit.MILLISECONDS.convert(timeout, unit));
    
public booleanisCancelled()

        if (mRequest == null) {
            return false;
        }
        return mRequest.isCanceled();
    
public synchronized booleanisDone()

        return mResultReceived || mException != null || isCancelled();
    
public static com.android.volley.toolbox.RequestFuturenewFuture()


         
        return new RequestFuture<E>();
    
public synchronized voidonErrorResponse(com.android.volley.VolleyError error)

        mException = error;
        notifyAll();
    
public synchronized voidonResponse(T response)

        mResultReceived = true;
        mResult = response;
        notifyAll();
    
public voidsetRequest(com.android.volley.Request request)

        mRequest = request;