public class RetryCounterImpl extends Object implements RetryCounter
RetryCounter
interface.Constructor and Description |
---|
RetryCounterImpl(int aRetryNumber)
Constructs a retry retry counter by providing the number of retries with
no delay before each retry.
|
RetryCounterImpl(int aRetryNumber,
long aRetryDelayInMs)
Constructs a retry timeout counter by providing the number of retries and
the delay before each retry.
|
RetryCounterImpl(int aRetryNumber,
long aRetryDelayInMs,
long aExpRetryDelayExtensionInMs)
Constructs a retry timeout counter by providing the number of retries and
the delay before each retry and taking an exponential delay extension
into calculation:
-------------------------------------------------------------------------
"(getRetryDelayInMs() + (Math.pow( 4, getRetryCount() - 1 ) * getExpRetryDelayExtensionInMs())"
-------------------------------------------------------------------------
In case a delay greater than 0 is set, then each retry is being delayed
by the according amount of milliseconds, in case no retries are left,
then delaying is skipped.
|
RetryCounterImpl(long aTotalDelayInMs,
long aRetryDelayInMs)
Constructs a retry timeout counter by providing the total delay time and
the delay before each retry.
|
Modifier and Type | Method and Description |
---|---|
void |
abort() |
long |
getCurrentRetryDelayInMs()
Returns the current delay before each retry to wait in milliseconds.
|
long |
getExpRetryDelayExtensionInMs()
Returns the exponential retry delay extension time in milliseconds.
|
long |
getInitialRetryDelayInMs()
Returns the initial delay before each retry to wait in milliseconds.
|
long |
getNextRetryDelayInMs()
Calculates the next retry delay in milliseconds.
|
int |
getRetryCount()
The current state regarding the retires.
|
int |
getRetryNumber()
Returns the number of retires this instance allows altogether.
|
boolean |
hasNextRetry()
Returns true in case not all retires have been used up.
|
boolean |
nextRetry()
Tests whether a next retry is possible.
|
void |
restart() |
void |
setRetryDelyInMs(long aRetryDelayInMs)
Sets the delay before each retry to wait in milliseconds.
|
public RetryCounterImpl(int aRetryNumber)
aRetryNumber
- Sets the number of retires this instance allows
altogetherpublic RetryCounterImpl(long aTotalDelayInMs, long aRetryDelayInMs)
RetryCounter
will delay till the last call of the
nextRetry()
. It does not take the time "lost" into account lost
by business logic calling the RetryCounter
. The actual
caclultated number of retires may be a rounded one, depending whether the
total delay divided by the retry delay has a reminder.
Basically speaking this is a convenience constructor calling
RetryCounterImpl(int, long, long)
calculating
the number of retires by:
-------------------------------------------------------------------------
"aRetryNumber = (aTotalDelayInMs / aRetryDelayInMs)"
-------------------------------------------------------------------------aTotalDelayInMs
- Sets the total delay time this instance allows
altogether. From this number divided by the actual retry delay
results in the number of retires.aRetryDelayInMs
- The delay before each retry to wait in
milliseconds. When less than or equal to 0, then the delay is
skipped.public RetryCounterImpl(int aRetryNumber, long aRetryDelayInMs)
aRetryNumber
- Sets the number of retires this instance allows
altogetheraRetryDelayInMs
- The delay before each retry to wait in
milliseconds. When less than or equal to 0, then the delay is
skipped.public RetryCounterImpl(int aRetryNumber, long aRetryDelayInMs, long aExpRetryDelayExtensionInMs)
aRetryNumber
- Sets the number of retires this instance allows
altogetheraRetryDelayInMs
- The delay before each retry to wait in
milliseconds. When less than or equal to 0, then the delay is
skipped.isExtendDelayTime
- Upon calling nextRetry()
, the retry
delay is extended by that exponential delay (being increased for
each retry).public boolean nextRetry()
RetryCounter
RetryCounter.nextRetry()
increments the retry
counter RetryCounter.getRetryCount()
to be 1 and not 0, so the retry counter
is actually a "try" counter, having the first "try" upon invoking
RetryCounter.nextRetry()
.
-------------------------------------------------------------------------nextRetry
in interface Retryable
nextRetry
in interface RetryCounter
Retryable.hasNextRetry()
.public long getNextRetryDelayInMs()
RetryCounter
RetryCounter.nextRetry()
method will wait in case its rules match for doing a
sleep.getNextRetryDelayInMs
in interface RetryCounter
public boolean hasNextRetry()
Retryable
hasNextRetry
in interface Retryable
public void restart()
restart
in interface org.refcodes.mixin.Restartable
public void abort()
abort
in interface org.refcodes.mixin.Abortable
public int getRetryNumber()
RetryCounter
getRetryNumber
in interface RetryCounter
public long getInitialRetryDelayInMs()
RetryCounter
RetryCounter.getCurrentRetryDelayInMs()
is calculated from the initial delay
and the exponential retry delay added for each retry (not added for the
first call to RetryCounter.nextRetry()
).getInitialRetryDelayInMs
in interface RetryCounter
public long getCurrentRetryDelayInMs()
RetryCounter
RetryCounter.getInitialRetryDelayInMs()
with the
RetryCounter.getExpRetryDelayExtensionInMs()
per retry.
-------------------------------------------------------------------------
The current retry delay gets incremented for each retry by an exponential
retry delay extension time calculated from in case it is greater than 0.
-------------------------------------------------------------------------getCurrentRetryDelayInMs
in interface RetryCounter
public long getExpRetryDelayExtensionInMs()
RetryCounter
RetryCounter.nextRetry()
is extended by that
exponential delay (being increased for each retry):
-------------------------------------------------------------------------
"(getRetryDelayInMs() + (Math.pow( 4, getRetryCount() - 1 ) * getExpRetryDelayExtensionInMs())"
-------------------------------------------------------------------------getExpRetryDelayExtensionInMs
in interface RetryCounter
public int getRetryCount()
RetryCounter
RetryCounter.nextRetry()
increments the retry
counter RetryCounter.getRetryCount()
to be 1 and not 0, so the retry counter
is actually a "try" counter, having the first "try" upon invoking
RetryCounter.nextRetry()
.
-------------------------------------------------------------------------getRetryCount
in interface Retryable
getRetryCount
in interface RetryCounter
public void setRetryDelyInMs(long aRetryDelayInMs)
aRetryDelayInMs
- The delay to be set in milliseconds.Copyright © 2016. All rights reserved.