Class AsynchronousValidator
- java.lang.Object
-
- org.apache.http.impl.client.cache.AsynchronousValidator
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
class AsynchronousValidator extends java.lang.Object implements java.io.Closeable
Class used for asynchronous revalidations to be used when the "stale- while-revalidate" directive is present
-
-
Field Summary
Fields Modifier and Type Field Description private CacheKeyGenerator
cacheKeyGenerator
private FailureCache
failureCache
private org.apache.commons.logging.Log
log
private java.util.Set<java.lang.String>
queued
private SchedulingStrategy
schedulingStrategy
-
Constructor Summary
Constructors Constructor Description AsynchronousValidator(CacheConfig config)
Create AsynchronousValidator which will make revalidation requests using anImmediateSchedulingStrategy
.AsynchronousValidator(SchedulingStrategy schedulingStrategy)
Create AsynchronousValidator which will make revalidation requests using the suppliedSchedulingStrategy
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
(package private) java.util.Set<java.lang.String>
getScheduledIdentifiers()
(package private) void
jobFailed(java.lang.String identifier)
The revalidation job did fail and thus the number of consecutive failed attempts will be increased.(package private) void
jobSuccessful(java.lang.String identifier)
The revalidation job was successful thus the number of consecutive failed attempts will be reset to zero.(package private) void
markComplete(java.lang.String identifier)
Removes an identifier from the internal list of revalidation jobs in progress.void
revalidateCacheEntry(CachingExec cachingExec, HttpRoute route, HttpRequestWrapper request, HttpClientContext context, HttpExecutionAware execAware, HttpCacheEntry entry)
Schedules an asynchronous revalidation
-
-
-
Field Detail
-
schedulingStrategy
private final SchedulingStrategy schedulingStrategy
-
queued
private final java.util.Set<java.lang.String> queued
-
cacheKeyGenerator
private final CacheKeyGenerator cacheKeyGenerator
-
failureCache
private final FailureCache failureCache
-
log
private final org.apache.commons.logging.Log log
-
-
Constructor Detail
-
AsynchronousValidator
public AsynchronousValidator(CacheConfig config)
Create AsynchronousValidator which will make revalidation requests using anImmediateSchedulingStrategy
. Its thread pool will be configured according to the givenCacheConfig
.- Parameters:
config
- specifies thread pool settings. SeeCacheConfig.getAsynchronousWorkersMax()
,CacheConfig.getAsynchronousWorkersCore()
,CacheConfig.getAsynchronousWorkerIdleLifetimeSecs()
, andCacheConfig.getRevalidationQueueSize()
.
-
AsynchronousValidator
AsynchronousValidator(SchedulingStrategy schedulingStrategy)
Create AsynchronousValidator which will make revalidation requests using the suppliedSchedulingStrategy
. Closing the validator will also close the given schedulingStrategy.- Parameters:
schedulingStrategy
- used to maintain a pool of worker threads and schedules when requests are executed
-
-
Method Detail
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
revalidateCacheEntry
public void revalidateCacheEntry(CachingExec cachingExec, HttpRoute route, HttpRequestWrapper request, HttpClientContext context, HttpExecutionAware execAware, HttpCacheEntry entry)
Schedules an asynchronous revalidation
-
markComplete
void markComplete(java.lang.String identifier)
Removes an identifier from the internal list of revalidation jobs in progress. This is meant to be called byAsynchronousValidationRequest.run()
once the revalidation is complete, using the identifier passed in during constructions.- Parameters:
identifier
-
-
jobSuccessful
void jobSuccessful(java.lang.String identifier)
The revalidation job was successful thus the number of consecutive failed attempts will be reset to zero. Should be called byAsynchronousValidationRequest.run()
.- Parameters:
identifier
- the revalidation job's unique identifier
-
jobFailed
void jobFailed(java.lang.String identifier)
The revalidation job did fail and thus the number of consecutive failed attempts will be increased. Should be called byAsynchronousValidationRequest.run()
.- Parameters:
identifier
- the revalidation job's unique identifier
-
getScheduledIdentifiers
java.util.Set<java.lang.String> getScheduledIdentifiers()
-
-