/** * Schedules an asynchronous revalidation * * @param target * @param request * @param context * @param entry */ public synchronized void revalidateCacheEntry(HttpHost target, HttpRequest request, HttpContext context, HttpCacheEntry entry) { // getVariantURI will fall back on getURI if no variants exist String uri = cacheKeyGenerator.getVariantURI(target, request, entry); if (!queued.contains(uri)) { AsynchronousValidationRequest revalidationRequest = new AsynchronousValidationRequest(this, cachingClient, target, request, context, entry, uri); try { executor.execute(revalidationRequest); queued.add(uri); } catch (RejectedExecutionException ree) { log.debug("Revalidation for [" + uri + "] not scheduled: " + ree); } } }
public void schedule( final AsynchronousValidationRequest revalidationRequest) { checkNotNull("revalidationRequest", revalidationRequest); final int consecutiveFailedAttempts = revalidationRequest.getConsecutiveFailedAttempts(); final long delayInMillis = calculateDelayInMillis(consecutiveFailedAttempts); executor.schedule(revalidationRequest, delayInMillis, TimeUnit.MILLISECONDS); }
/** * Revalidate the cache entry and return if the operation was successful. * Success means a connection to the server was established and replay did * not indicate a server error. * @return <code>true</code> if the cache entry was successfully validated; * otherwise <code>false</code> */ protected boolean revalidateCacheEntry() { try { final CloseableHttpResponse httpResponse = cachingExec.revalidateCacheEntry(route, request, context, execAware, cacheEntry); try { final int statusCode = httpResponse.getStatusLine().getStatusCode(); return isNotServerError(statusCode) && isNotStale(httpResponse); } finally { httpResponse.close(); } } catch (final IOException ioe) { log.debug("Asynchronous revalidation failed due to I/O error", ioe); return false; } catch (final HttpException pe) { log.error("HTTP protocol exception during asynchronous revalidation", pe); return false; } catch (final RuntimeException re) { log.error("RuntimeException thrown during asynchronous revalidation: " + re); return false; } }
public void run() { try { if (revalidateCacheEntry()) { parent.jobSuccessful(identifier); } else { parent.jobFailed(identifier); } } finally { parent.markComplete(identifier); } }
/** * Schedules an asynchronous revalidation */ public synchronized void revalidateCacheEntry( final CachingExec cachingExec, final HttpRoute route, final HttpRequestWrapper request, final HttpClientContext context, final HttpExecutionAware execAware, final HttpCacheEntry entry) { // getVariantURI will fall back on getURI if no variants exist final String uri = cacheKeyGenerator.getVariantURI(context.getTargetHost(), request, entry); if (!queued.contains(uri)) { final int consecutiveFailedAttempts = failureCache.getErrorCount(uri); final AsynchronousValidationRequest revalidationRequest = new AsynchronousValidationRequest( this, cachingExec, route, request, context, execAware, entry, uri, consecutiveFailedAttempts); try { schedulingStrategy.schedule(revalidationRequest); queued.add(uri); } catch (final RejectedExecutionException ree) { log.debug("Revalidation for [" + uri + "] not scheduled: " + ree); } } }