Home | History | Annotate | Download | only in volley

Lines Matching refs:Request

41     private final BlockingQueue<Request<?>> mCacheQueue;
44 private final BlockingQueue<Request<?>> mNetworkQueue;
68 BlockingQueue<Request<?>> cacheQueue, BlockingQueue<Request<?>> networkQueue,
107 // This is needed to avoid keeping previous request references alive for an indeterminate amount
111 // Get a request from the cache triage queue, blocking until
113 final Request<?> request = mCacheQueue.take();
114 request.addMarker("cache-queue-take");
116 // If the request has been canceled, don't bother dispatching it.
117 if (request.isCanceled()) {
118 request.finish("cache-discard-canceled");
123 Cache.Entry entry = mCache.get(request.getCacheKey());
125 request.addMarker("cache-miss");
127 if (!mWaitingRequestManager.maybeAddToWaitingRequests(request)) {
128 mNetworkQueue.put(request);
135 request.addMarker("cache-hit-expired");
136 request.setCacheEntry(entry);
137 if (!mWaitingRequestManager.maybeAddToWaitingRequests(request)) {
138 mNetworkQueue.put(request);
143 // We have a cache hit; parse its data for delivery back to the request.
144 request.addMarker("cache-hit");
145 Response<?> response = request.parseNetworkResponse(
147 request.addMarker("cache-hit-parsed");
151 mDelivery.postResponse(request, response);
154 // but we need to also send the request to the network for
156 request.addMarker("cache-hit-refresh-needed");
157 request.setCacheEntry(entry);
161 if (!mWaitingRequestManager.maybeAddToWaitingRequests(request)) {
163 // the delivery then forward the request along to the network.
164 mDelivery.postResponse(request, response, new Runnable() {
168 mNetworkQueue.put(request);
176 // request has been added to list of waiting requests
177 // to receive the network response from the first request once it returns.
178 mDelivery.postResponse(request, response);
183 private static class WaitingRequestManager implements Request.NetworkRequestCompleteListener {
186 * Staging area for requests that already have a duplicate request in flight.
189 * <li>containsKey(cacheKey) indicates that there is a request in flight for the given cache
191 * <li>get(cacheKey) returns waiting requests for the given cache key. The in flight request
195 private final Map<String, List<Request<?>>> mWaitingRequests = new HashMap<>();
203 /** Request received a valid response that can be used by other waiting requests. */
205 public void onResponseReceived(Request<?> request, Response<?> response) {
207 onNoUsableResponseReceived(request);
210 String cacheKey = request.getCacheKey();
211 List<Request<?>> waitingRequests;
221 for (Request<?> waiting : waitingRequests) {
229 public synchronized void onNoUsableResponseReceived(Request<?> request) {
230 String cacheKey = request.getCacheKey();
231 List<Request<?>> waitingRequests = mWaitingRequests.remove(cacheKey);
237 Request<?> nextInLine = waitingRequests.remove(0);
243 VolleyLog.e("Couldn't add request to queue. %s", iex.toString());
253 * For cacheable requests, if a request for the same cache key is already in flight,
254 * add it to a queue to wait for that in-flight request to finish.
255 * @return whether the request was queued. If false, we should continue issuing the request
256 * over the network. If true, we should put the request on hold to be processed when
257 * the in-flight request finishes.
259 private synchronized boolean maybeAddToWaitingRequests(Request<?> request) {
260 String cacheKey = request.getCacheKey();
261 // Insert request into stage if there's already a request with the same cache key
264 // There is already a request in flight. Queue up.
265 List<Request<?>> stagedRequests = mWaitingRequests.get(cacheKey);
267 stagedRequests = new ArrayList<Request<?>>();
269 request.addMarker("waiting-for-response");
270 stagedRequests.add(request);
273 VolleyLog.d("Request for cacheKey=%s is in flight, putting on hold.", cacheKey);
277 // Insert 'null' queue for this cacheKey, indicating there is now a request in
280 request.setNetworkRequestCompleteListener(this);
282 VolleyLog.d("new request, sending to network %s", cacheKey);