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.
|
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 |
getSequenceNumber()
Gets a sequence number.
|
<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.
|
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 servicepublic <T> void addRequestFinishedListener(RequestQueue.RequestFinishedListener<T> listener)
public <T> void removeRequestFinishedListener(RequestQueue.RequestFinishedListener<T> listener)