org.apache.http.impl.client.cache
Class ExponentialBackOffSchedulingStrategy
java.lang.Object
org.apache.http.impl.client.cache.ExponentialBackOffSchedulingStrategy
- All Implemented Interfaces:
- Closeable, SchedulingStrategy
@ThreadSafe
public class ExponentialBackOffSchedulingStrategy
- extends Object
- implements SchedulingStrategy
An implementation that backs off exponentially based on the number of
consecutive failed attempts stored in the
AsynchronousValidationRequest
. 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 (= 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()
)
The following equation is used to calculate the delay for a specific revalidation request:
delay = getInitialExpiryInMillis()
* Math.pow(getBackOffRate()
, AsynchronousValidationRequest#getConsecutiveFailedAttempts()
- 1))
The resulting delay won't exceed getMaxExpiryInMillis()
.
- Since:
- 4.3
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
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
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; not null
- 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; not null
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
schedule
public void schedule(org.apache.http.impl.client.cache.AsynchronousValidationRequest revalidationRequest)
- Description copied from interface:
SchedulingStrategy
- Schedule an
AsynchronousValidationRequest
to be executed.
- Specified by:
schedule
in interface SchedulingStrategy
- Parameters:
revalidationRequest
- the request to be executed; not null
close
public void close()
- Specified by:
close
in interface Closeable
getBackOffRate
public long getBackOffRate()
getInitialExpiryInMillis
public long getInitialExpiryInMillis()
getMaxExpiryInMillis
public long getMaxExpiryInMillis()
calculateDelayInMillis
protected long calculateDelayInMillis(int consecutiveFailedAttempts)
checkNotNull
protected static <T> T checkNotNull(String parameterName,
T value)
checkNotNegative
protected static long checkNotNegative(String parameterName,
long value)
Copyright © 2010-2013 The Apache Software Foundation. All Rights Reserved.