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(RequestFilter). |
static interface |
RequestQueue.RequestFinishedListener<T>
Callback interface for completed requests.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_NETWORK_THREAD_POOL_SIZE
Number of network request dispatcher threads to start.
|
protected Cache |
mCache
Cache interface for retrieving and storing responses.
|
protected CacheDispatcher |
mCacheDispatcher
The cache dispatcher.
|
protected java.util.concurrent.PriorityBlockingQueue<Request<?>> |
mCacheQueue
The cache triage queue.
|
protected ResponseDelivery |
mDelivery
Response delivery mechanism.
|
protected NetworkDispatcher[] |
mDispatchers
The network dispatchers.
|
protected Network |
mNetwork
Network interface for performing requests.
|
protected java.util.concurrent.PriorityBlockingQueue<Request<?>> |
mNetworkQueue
The queue of requests that are actually going out to the network.
|
| 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.
|
<T> void |
addRequestFinishedListener(RequestQueue.RequestFinishedListener<T> listener) |
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.
|
Cache |
getCache()
Gets the
Cache instance being used. |
int |
getCurrentRequests() |
int |
getSequenceNumber()
Gets a sequence number.
|
int |
getWaitingRequests() |
<T> void |
removeRequestFinishedListener(RequestQueue.RequestFinishedListener<T> listener)
Remove a RequestFinishedListener.
|
void |
start()
Starts the dispatchers in this queue.
|
void |
stop()
Stops the cache and network dispatchers.
|
RequestQueue |
withCacheDspather(CacheDispatcher cacheDspather) |
protected final java.util.concurrent.PriorityBlockingQueue<Request<?>> mCacheQueue
protected final java.util.concurrent.PriorityBlockingQueue<Request<?>> mNetworkQueue
public static final int DEFAULT_NETWORK_THREAD_POOL_SIZE
protected final Cache mCache
protected final Network mNetwork
protected final ResponseDelivery mDelivery
protected NetworkDispatcher[] mDispatchers
protected 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 RequestQueue withCacheDspather(CacheDispatcher cacheDspather)
public 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 servicepublic <T> void addRequestFinishedListener(RequestQueue.RequestFinishedListener<T> listener)
public <T> void removeRequestFinishedListener(RequestQueue.RequestFinishedListener<T> listener)
public int getCurrentRequests()
public int getWaitingRequests()