Package org.refcodes.controlflow
Class RetryTimeoutImpl
- java.lang.Object
-
- org.refcodes.controlflow.RetryTimeoutImpl
-
- All Implemented Interfaces:
Retryable
,RetryTimeout
,org.refcodes.mixin.Abortable
,org.refcodes.mixin.Restartable
public class RetryTimeoutImpl extends java.lang.Object implements RetryTimeout
Implementation of theRetryTimeout
interface.
-
-
Constructor Summary
Constructors Constructor Description RetryTimeoutImpl(long aTimeoutInMs, int aRetryLoops)
Constructs theRetryTimeoutImpl
with the given timeout and the given number of retry loops.RetryTimeoutImpl(long aTimeoutInMs, long aRetryDelayInMs)
Constructs theRetryTimeoutImpl
with the given timeout and the given retry delay.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abort()
int
getRetryCount()
The current state regarding the retires.long
getRetryDelayInMs()
Returns retry to wait in milliseconds upon callingRetryable.nextRetry()
).long
getTimeoutInMs()
Returns the timeout altogether theRetryTimeout
is waiting while iterating through theRetryTimeout
viaRetryable.hasNextRetry()
andRetryable.nextRetry()
.boolean
hasNextRetry()
Returns true in case not all retires have been used up.boolean
nextRetry()
Tests whether a next retry is possible.boolean
nextRetry(java.lang.Object aMonitor)
Tests whether a next retry is possible.void
restart()
-
-
-
Constructor Detail
-
RetryTimeoutImpl
public RetryTimeoutImpl(long aTimeoutInMs, long aRetryDelayInMs)
Constructs theRetryTimeoutImpl
with the given timeout and the given retry delay. The retry number is round about: ------------------------------------------------------------------------- "aTimeoutInMs / aRetryDelayInMs" ------------------------------------------------------------------------- CAUTION: The above mentioned is not necessarily so, in case your business logic inside the loop iterations is slow, then less retries fit in the given timeout.- Parameters:
aTimeoutInMs
- The total time in milliseconds all iterations together will delay.aRetryDelayInMs
- The delay before each retry to wait in milliseconds.
-
RetryTimeoutImpl
public RetryTimeoutImpl(long aTimeoutInMs, int aRetryLoops)
Constructs theRetryTimeoutImpl
with the given timeout and the given number of retry loops. The retry delay is round about: ------------------------------------------------------------------------- "aTimeoutInMs / aRetryLoops" ------------------------------------------------------------------------- CAUTION: The above mentioned is not necessarily so, in case your business logic inside the loop iterations is slow, then less retries fit in the given timeout.- Parameters:
aTimeoutInMs
- The total time in milliseconds all iterations together will delay.aRetryLoops
- The number of retries, each retry delay before each retry to wait in milliseconds is about the timeout divided by the retry number.
-
-
Method Detail
-
nextRetry
public boolean nextRetry()
Tests whether a next retry is possible. In case this is the case, then the thread is delayed by the configured (implementation specific) delay time.- Specified by:
nextRetry
in interfaceRetryable
- Returns:
- True in case there is a next retry as of
Retryable.hasNextRetry()
.
-
nextRetry
public boolean nextRetry(java.lang.Object aMonitor)
Tests whether a next retry is possible. In case this is the case, then the thread is delayed by the configured (implementation specific) delay time or until the provided monitor is notified viaObject.notify()
orObject.notifyAll()
. Similar to theRetryable.nextRetry()
with the difference of accepting a dedicated monitor which is used for aborting the dellay.- Specified by:
nextRetry
in interfaceRetryTimeout
- Parameters:
aMonitor
- the monitor- Returns:
- True in case there is a next retry as of
Retryable.hasNextRetry()
.
-
hasNextRetry
public boolean hasNextRetry()
Returns true in case not all retires have been used up.- Specified by:
hasNextRetry
in interfaceRetryable
- Returns:
- True in case there are retries left true in case all retries elapsed.
-
getRetryCount
public int getRetryCount()
The current state regarding the retires. It specifies at which retry we currently are.- Specified by:
getRetryCount
in interfaceRetryable
- Returns:
- The number of retries used up so far.
-
abort
public void abort()
- Specified by:
abort
in interfaceorg.refcodes.mixin.Abortable
-
restart
public void restart()
- Specified by:
restart
in interfaceorg.refcodes.mixin.Restartable
-
getTimeoutInMs
public long getTimeoutInMs()
Returns the timeout altogether theRetryTimeout
is waiting while iterating through theRetryTimeout
viaRetryable.hasNextRetry()
andRetryable.nextRetry()
. The actual timeout being waited is the effective time elapsed from the first call toRetryable.nextRetry()
till the last call toRetryable.nextRetry()
. Any delay inside the iteration loop is not added up to the delay.- Specified by:
getTimeoutInMs
in interfaceRetryTimeout
- Returns:
- The
-
getRetryDelayInMs
public long getRetryDelayInMs()
Returns retry to wait in milliseconds upon callingRetryable.nextRetry()
).- Specified by:
getRetryDelayInMs
in interfaceRetryTimeout
- Returns:
- The delay being set in milliseconds.
-
-