Class ExponentialBackOffSchedulingStrategy
- java.lang.Object
-
- org.apache.http.impl.client.cache.ExponentialBackOffSchedulingStrategy
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,SchedulingStrategy
@Contract(threading=SAFE) public class ExponentialBackOffSchedulingStrategy extends java.lang.Object implements SchedulingStrategy
An implementation that backs off exponentially based on the number of consecutive failed attempts stored in theAsynchronousValidationRequest
. It uses the following defaults:no delay in case it was never tried or didn't fail so far 6 secs delay for one failed attempt (=
The following equation is used to calculate the delay for a specific revalidation request:getInitialExpiryInMillis()
) 60 secs delay for two failed attempts 10 mins delay for three failed attempts 100 mins delay for four failed attempts ~16 hours delay for five failed attempts 24 hours delay for six or more failed attempts (=getMaxExpiryInMillis()
)delay =
The resulting delay won't exceedgetInitialExpiryInMillis()
* Math.pow(getBackOffRate()
,AsynchronousValidationRequest.getConsecutiveFailedAttempts()
- 1))getMaxExpiryInMillis()
.- Since:
- 4.3
-
-
Field Summary
Fields Modifier and Type Field Description private long
backOffRate
static long
DEFAULT_BACK_OFF_RATE
static long
DEFAULT_INITIAL_EXPIRY_IN_MILLIS
static long
DEFAULT_MAX_EXPIRY_IN_MILLIS
private java.util.concurrent.ScheduledExecutorService
executor
private long
initialExpiryInMillis
private long
maxExpiryInMillis
-
Constructor Summary
Constructors Constructor Description ExponentialBackOffSchedulingStrategy(java.util.concurrent.ScheduledExecutorService executor, long backOffRate, long initialExpiryInMillis, long maxExpiryInMillis)
ExponentialBackOffSchedulingStrategy(CacheConfig cacheConfig)
Create a new scheduling strategy using a fixed pool of worker threads.ExponentialBackOffSchedulingStrategy(CacheConfig cacheConfig, long backOffRate, long initialExpiryInMillis, long maxExpiryInMillis)
Create a new scheduling strategy by using a fixed pool of worker threads and the given parameters to calculated the delay.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected long
calculateDelayInMillis(int consecutiveFailedAttempts)
protected static long
checkNotNegative(java.lang.String parameterName, long value)
Deprecated.UseArgs.notNegative(long, String)
protected static <T> T
checkNotNull(java.lang.String parameterName, T value)
Deprecated.UseArgs.notNull(Object, String)
void
close()
private static java.util.concurrent.ScheduledThreadPoolExecutor
createThreadPoolFromCacheConfig(CacheConfig cacheConfig)
long
getBackOffRate()
long
getInitialExpiryInMillis()
long
getMaxExpiryInMillis()
void
schedule(AsynchronousValidationRequest revalidationRequest)
Schedule anAsynchronousValidationRequest
to be executed.
-
-
-
Field Detail
-
DEFAULT_BACK_OFF_RATE
public static final long DEFAULT_BACK_OFF_RATE
- See Also:
- Constant Field Values
-
DEFAULT_INITIAL_EXPIRY_IN_MILLIS
public static final long DEFAULT_INITIAL_EXPIRY_IN_MILLIS
-
DEFAULT_MAX_EXPIRY_IN_MILLIS
public static final long DEFAULT_MAX_EXPIRY_IN_MILLIS
-
backOffRate
private final long backOffRate
-
initialExpiryInMillis
private final long initialExpiryInMillis
-
maxExpiryInMillis
private final long maxExpiryInMillis
-
executor
private final java.util.concurrent.ScheduledExecutorService executor
-
-
Constructor Detail
-
ExponentialBackOffSchedulingStrategy
public ExponentialBackOffSchedulingStrategy(CacheConfig cacheConfig)
Create a new scheduling strategy using a fixed pool of worker threads.- Parameters:
cacheConfig
- the thread pool configuration to be used; notnull
- See Also:
CacheConfig.getAsynchronousWorkersMax()
,DEFAULT_BACK_OFF_RATE
,DEFAULT_INITIAL_EXPIRY_IN_MILLIS
,DEFAULT_MAX_EXPIRY_IN_MILLIS
-
ExponentialBackOffSchedulingStrategy
public ExponentialBackOffSchedulingStrategy(CacheConfig cacheConfig, long backOffRate, long initialExpiryInMillis, long maxExpiryInMillis)
Create a new scheduling strategy by using a fixed pool of worker threads and the given parameters to calculated the delay.- Parameters:
cacheConfig
- the thread pool configuration to be used; notnull
backOffRate
- the back off rate to be used; not negativeinitialExpiryInMillis
- the initial expiry in milli seconds; not negativemaxExpiryInMillis
- the upper limit of the delay in milli seconds; not negative- See Also:
CacheConfig.getAsynchronousWorkersMax()
,ExponentialBackOffSchedulingStrategy
-
ExponentialBackOffSchedulingStrategy
ExponentialBackOffSchedulingStrategy(java.util.concurrent.ScheduledExecutorService executor, long backOffRate, long initialExpiryInMillis, long maxExpiryInMillis)
-
-
Method Detail
-
createThreadPoolFromCacheConfig
private static java.util.concurrent.ScheduledThreadPoolExecutor createThreadPoolFromCacheConfig(CacheConfig cacheConfig)
-
schedule
public void schedule(AsynchronousValidationRequest revalidationRequest)
Description copied from interface:SchedulingStrategy
Schedule anAsynchronousValidationRequest
to be executed.- Specified by:
schedule
in interfaceSchedulingStrategy
- Parameters:
revalidationRequest
- the request to be executed; notnull
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
-
getBackOffRate
public long getBackOffRate()
-
getInitialExpiryInMillis
public long getInitialExpiryInMillis()
-
getMaxExpiryInMillis
public long getMaxExpiryInMillis()
-
calculateDelayInMillis
protected long calculateDelayInMillis(int consecutiveFailedAttempts)
-
checkNotNull
@Deprecated protected static <T> T checkNotNull(java.lang.String parameterName, T value)
Deprecated.UseArgs.notNull(Object, String)
-
checkNotNegative
@Deprecated protected static long checkNotNegative(java.lang.String parameterName, long value)
Deprecated.UseArgs.notNegative(long, String)
-
-