@Contract(threading=SAFE) public class ExponentialBackOffSchedulingStrategy extends Object implements SchedulingStrategy
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().| Modifier and Type | Field and Description |
|---|---|
static long |
DEFAULT_BACK_OFF_RATE |
static long |
DEFAULT_INITIAL_EXPIRY_IN_MILLIS |
static long |
DEFAULT_MAX_EXPIRY_IN_MILLIS |
| Constructor and Description |
|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
protected long |
calculateDelayInMillis(int consecutiveFailedAttempts) |
protected static long |
checkNotNegative(String parameterName,
long value)
Deprecated.
Use
Args.notNegative(long, String) |
protected static <T> T |
checkNotNull(String parameterName,
T value)
Deprecated.
Use
Args.notNull(Object, String) |
void |
close() |
long |
getBackOffRate() |
long |
getInitialExpiryInMillis() |
long |
getMaxExpiryInMillis() |
void |
schedule(AsynchronousValidationRequest revalidationRequest)
Schedule an
AsynchronousValidationRequest to be executed. |
public static final long DEFAULT_BACK_OFF_RATE
public static final long DEFAULT_INITIAL_EXPIRY_IN_MILLIS
public static final long DEFAULT_MAX_EXPIRY_IN_MILLIS
public ExponentialBackOffSchedulingStrategy(CacheConfig cacheConfig)
cacheConfig - the thread pool configuration to be used; not nullCacheConfig.getAsynchronousWorkersMax(),
DEFAULT_BACK_OFF_RATE,
DEFAULT_INITIAL_EXPIRY_IN_MILLIS,
DEFAULT_MAX_EXPIRY_IN_MILLISpublic ExponentialBackOffSchedulingStrategy(CacheConfig cacheConfig, long backOffRate, long initialExpiryInMillis, long maxExpiryInMillis)
cacheConfig - the thread pool configuration to be used; not nullbackOffRate - 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 negativeCacheConfig.getAsynchronousWorkersMax(),
ExponentialBackOffSchedulingStrategypublic void schedule(AsynchronousValidationRequest revalidationRequest)
SchedulingStrategyAsynchronousValidationRequest to be executed.schedule in interface SchedulingStrategyrevalidationRequest - the request to be executed; not nullpublic void close()
close in interface Closeableclose in interface AutoCloseablepublic long getBackOffRate()
public long getInitialExpiryInMillis()
public long getMaxExpiryInMillis()
protected long calculateDelayInMillis(int consecutiveFailedAttempts)
@Deprecated protected static <T> T checkNotNull(String parameterName, T value)
Args.notNull(Object, String)@Deprecated protected static long checkNotNegative(String parameterName, long value)
Args.notNegative(long, String)Copyright © 1999–2022 The Apache Software Foundation. All rights reserved.