public class RequestQueue
extends java.lang.Object
add(Request)
will enqueue the given Request for dispatch,
resolving from either cache or network on a worker thread, and then delivering
a parsed response on the main thread.Modifier and Type | Class and Description |
---|---|
static interface |
RequestQueue.RequestFilter
A simple predicate or filter interface for Requests, for use by
cancelAll(com.android.volley.RequestQueue.RequestFilter) . |
Modifier and Type | Field and Description |
---|---|
private static int |
DEFAULT_NETWORK_THREAD_POOL_SIZE
Number of network request dispatcher threads to start.
|
private Cache |
mCache
Cache interface for retrieving and storing responses.
|
private CacheDispatcher |
mCacheDispatcher
The cache dispatcher.
|
private java.util.concurrent.PriorityBlockingQueue<Request<?>> |
mCacheQueue
The cache triage queue.
|
private java.util.Set<Request<?>> |
mCurrentRequests
The set of all requests currently being processed by this RequestQueue.
|
private ResponseDelivery |
mDelivery
Response delivery mechanism.
|
private NetworkDispatcher[] |
mDispatchers
The network dispatchers.
|
private Network |
mNetwork
Network interface for performing requests.
|
private java.util.concurrent.PriorityBlockingQueue<Request<?>> |
mNetworkQueue
The queue of requests that are actually going out to the network.
|
private java.util.concurrent.atomic.AtomicInteger |
mSequenceGenerator
Used for generating monotonically-increasing sequence numbers for requests.
|
private java.util.Map<java.lang.String,java.util.Queue<Request<?>>> |
mWaitingRequests
Staging area for requests that already have a duplicate request in flight.
|
Constructor and Description |
---|
RequestQueue(Cache cache,
Network network)
Creates the worker pool.
|
RequestQueue(Cache cache,
Network network,
int threadPoolSize)
Creates the worker pool.
|
RequestQueue(Cache cache,
Network network,
int threadPoolSize,
ResponseDelivery delivery)
Creates the worker pool.
|
Modifier and Type | Method and Description |
---|---|
<T> Request<T> |
add(Request<T> request)
Adds a Request to the dispatch queue.
|
void |
cancelAll(java.lang.Object tag)
Cancels all requests in this queue with the given tag.
|
void |
cancelAll(RequestQueue.RequestFilter filter)
Cancels all requests in this queue for which the given filter applies.
|
(package private) void |
finish(Request<?> request)
Called from
Request.finish(String) , indicating that processing of the given request
has finished. |
Cache |
getCache()
Gets the
Cache instance being used. |
int |
getSequenceNumber()
Gets a sequence number.
|
void |
start()
Starts the dispatchers in this queue.
|
void |
stop()
Stops the cache and network dispatchers.
|
private java.util.concurrent.atomic.AtomicInteger mSequenceGenerator
private final java.util.Map<java.lang.String,java.util.Queue<Request<?>>> mWaitingRequests
private final java.util.Set<Request<?>> mCurrentRequests
private final java.util.concurrent.PriorityBlockingQueue<Request<?>> mCacheQueue
private final java.util.concurrent.PriorityBlockingQueue<Request<?>> mNetworkQueue
private static final int DEFAULT_NETWORK_THREAD_POOL_SIZE
private final Cache mCache
private final Network mNetwork
private final ResponseDelivery mDelivery
private NetworkDispatcher[] mDispatchers
private CacheDispatcher mCacheDispatcher
public RequestQueue(Cache cache, Network network, int threadPoolSize, ResponseDelivery delivery)
start()
is called.cache
- A Cache to use for persisting responses to disknetwork
- A Network interface for performing HTTP requeststhreadPoolSize
- Number of network dispatcher threads to createdelivery
- A ResponseDelivery interface for posting responses and errorspublic RequestQueue(Cache cache, Network network, int threadPoolSize)
start()
is called.cache
- A Cache to use for persisting responses to disknetwork
- A Network interface for performing HTTP requeststhreadPoolSize
- Number of network dispatcher threads to createpublic void start()
public void stop()
public int getSequenceNumber()
public void cancelAll(RequestQueue.RequestFilter filter)
filter
- The filtering function to usepublic void cancelAll(java.lang.Object tag)
public <T> Request<T> add(Request<T> request)
request
- The request to servicevoid finish(Request<?> request)
Request.finish(String)
, indicating that processing of the given request
has finished.
Releases waiting requests for request.getCacheKey()
if
request.shouldCache()
.