Starts the runnable for batched delivery of responses if it is not already started.
@param cacheKey The cacheKey of the response being delivered.
@param request The BatchedImageRequest to be delivered.
494907
private void batchResponse(String cacheKey, BatchedImageRequest request) {
        batchedResponses.put(cacheKey, request);
        // If we don't already have a batch delivery runnable in flight, make a new one.
        // Note that this will be used to deliver responses to all callers in batchedResponses.
        if (runnable == null) {
            runnable = new Runnable() {
                @Override
                public void run() {
                    for (BatchedImageRequest bir : batchedResponses.values()) {
                        for (ImageContainer container : bir.mContainers) {
                            // If one of the callers in the batched request canceled the request
                            // after the response was received but before it was delivered,
                            // skip them.
                            if (container.mListener == null) {
                                continue;
                            }
                            if (bir.getError() == null) {
                                container.mBitmap = bir.mResponseBitmap;
                                container.mListener.onResponse(container, false);
                            } else {
                                container.mListener.onError(bir.getError());
                            }
                        }
                    }
                    batchedResponses.clear();
                    runnable = null;
                }

            };
            // Post the runnable.
            handler.postDelayed(runnable, batchResponseDelayMs);
        }
    }
64988
public <T> void notifyObserversOfRequestSuccess(CachedSpiceRequest<T> request) {
        RequestProcessingContext requestProcessingContext = new RequestProcessingContext();
        requestProcessingContext.setExecutionThread(Thread.currentThread());
        post(new RequestSucceededNotifier<T>(request, spiceServiceListenerList, requestProcessingContext));
    }
960484
public void notifyObserversOfRequestCancellation(CachedSpiceRequest<?> request) {
        RequestProcessingContext requestProcessingContext = new RequestProcessingContext();
        requestProcessingContext.setExecutionThread(Thread.currentThread());
        post(new RequestCancelledNotifier(request, spiceServiceListenerList, requestProcessingContext));
    }
315993
private CompletableFuture<ExecuteResponse> execute(ExecuteRequest request) {
    return getService(request).thenCompose(service -> service.execute(request));
  }
859558
@Override
	protected void preparePaintComponent(final Request request) {
		super.preparePaintComponent(request);

		if (isAjax() && UIContextHolder.getCurrent().getUI() != null) {
			AjaxTarget target = getAjaxTarget();
			AjaxHelper.registerComponent(target.getId(), getId());
		}

		String cacheKey = getListCacheKey();

		if (cacheKey != null) {
			LookupTableHelper.registerList(cacheKey, request);
		}
	}
212623
public void performPersistCursorRequest(String name, long key, Request request) {
        persistentRequests.send(new PersistentRequestsActor.PerformCursorRequest(name, key, request));
    }
1049810
public void notifyObserversOfRequestProgress(CachedSpiceRequest<?> request, RequestProgress requestProgress) {
        RequestProcessingContext requestProcessingContext = new RequestProcessingContext();
        requestProcessingContext.setExecutionThread(Thread.currentThread());
        requestProcessingContext.setRequestProgress(requestProgress);
        post(new RequestProgressNotifier(request, spiceServiceListenerList, requestProcessingContext));
    }
388379
@Override
    public CacheKey getCacheKey(HttpServletRequest request, HttpServletResponse response)
            throws IllegalStateException {
        if (this.wrappedComponent != null) {
            return this.wrappedComponent.getCacheKey(request, response);
        } else {
            logger.debug("PipelineComponentWrapper.wrapperComponent is null");
            throw new IllegalStateException("PipelineComponentWrapper.wrapperComponent is null");
        }
    }
534831
protected void deliveryAsyncResult(Request request, HttpCallback<?> callback) {
        Util.log("onDelivery:" + request.url().toString());
        final HttpCallback<?> resCallBack = callback == null ? new DefaultCallback() : callback;

        //Call start
        callStart(resCallBack, request);

        mOkHttpClient.newCall(request).enqueue(new Callback() {
            public void onFailure(Call call, IOException e) {
                Util.log("onFailure:" + call.request().toString());
                callFailure(resCallBack, call.request(), null, e);
                callFinish(resCallBack);
            }

            public void onResponse(Call call, Response response) {
                try {
                    Object ret = null;
                    final String string = response.body().string();
                    final boolean haveValue = !TextUtils.isEmpty(string);

                    Util.log("onResponse:Code:%d Body:%s.", response.code(), (haveValue ? string : "null"));

                    if (haveValue) {
                        ret = mResolver.analysis(string, resCallBack.getClass());
                    }

                    callSuccess(resCallBack, ret, response.code());
                } catch (Exception e) {
                    Util.log("onResponse Failure:" + response.request().toString());
                    callFailure(resCallBack, response.request(), response, e);
                }
                callFinish(resCallBack);
            }
        });
    }
1027194
public static void bind(HttpServletRequest request) {
        if (request != null && threadLocal.get() != null) {
            throw new IllegalStateException("HttpServletRequestHolder.bind() called for a "
                    + "thread that already has a request associated with it. It's likely that the request "
                    + "was not correctly removed from the thread before it is put back into the thread pool.");
        }
        threadLocal.set(request);
    }
486805
public CompletableFuture<ExecuteResponse> execute(ExecuteRequest request) {
    logRequest(request);
    return CompletableFuture.completedFuture(logResponse(ExecuteResponse.error()));
  }
1187604
protected final void crawl(final CrawlRequest request) {
        Validate.validState(!isStopped,
                "The crawler is not started. Maybe you meant to add this request as a crawl seed?");
        Validate.validState(!isStopping, "Cannot add request when the crawler is stopping.");
        Validate.notNull(request, "The request cannot be null.");

        crawlFrontier.feedRequest(request, false);
    }
313596
private void executeStorageRead(Request request) {
        try {
            byte[] buffer = new byte[request.length];
            getHandle()
                    .thenComposeAsync(handle -> this.storage.read(handle, request.offset, buffer, 0, buffer.length, request.getTimeout()), this.executor)
                    .thenAcceptAsync(bytesRead -> request.complete(new ByteArraySegment(buffer, 0, bytesRead)), this.executor)
                    .whenComplete((r, ex) -> {
                        if (ex != null) {
                            request.fail(ex);
                        }

                        // Unregister the Request after every request fulfillment.
                        finalizeRequest(request);
                    });
        } catch (Throwable ex) {
            if (Exceptions.mustRethrow(ex)) {
                throw ex;
            }

            request.fail(ex);
            finalizeRequest(request);
        }
    }
100726
private void start(Runnable timeoutTask) {
        long timeout = timeoutPolicy.getTimeout().toNanos();
        start(timeoutTask, timeout);
    }
895077
public void notifyObserversOfRequestNotFound(CachedSpiceRequest<?> request) {
        RequestProcessingContext requestProcessingContext = new RequestProcessingContext();
        requestProcessingContext.setExecutionThread(Thread.currentThread());
        post(new RequestNotFoundNotifier(request, spiceServiceListenerList, requestProcessingContext));
    }
48661
public static void downloadAsync(ImageRequest request) {
        if (request == null) {
            return;
        }

        // NOTE: This is the ONLY place where the original request's Url is read. From here on,
        // we will keep track of the Url separately. This is because we might be dealing with a
        // redirect response and the Url might change. We can't create our own new ImageRequests
        // for these changed Urls since the caller might be doing some book-keeping with the request's
        // object reference. So we keep the old references and just map them to new urls in the downloader
        RequestKey key = new RequestKey(request.getImageUri(), request.getCallerTag());
        synchronized (pendingRequests) {
            DownloaderContext downloaderContext = pendingRequests.get(key);
            if (downloaderContext != null) {
                downloaderContext.request = request;
                downloaderContext.isCancelled = false;
                downloaderContext.workItem.moveToFront();
            } else {
                enqueueCacheRead(request, key, request.isCachedRedirectAllowed());
            }
        }
    }
328820
@Override
    public final CacheKey getCacheKey(HttpServletRequest request, HttpServletResponse response) {
        final CacheKeyBuilder<String, String> cacheKeyBuilder = CacheKey.builder(getName());

        final PreferencesScope stylesheetPreferencesScope =
                this.getStylesheetPreferencesScope(request);

        this.stylesheetUserPreferencesService.populateStylesheetParameters(
                request, stylesheetPreferencesScope, cacheKeyBuilder);

        this.stylesheetUserPreferencesService.populateOutputProperties(
                request, stylesheetPreferencesScope, cacheKeyBuilder);

        return cacheKeyBuilder.build();
    }