T
- the return parameter of retriableCall()
public abstract class Retriable<T> extends Object
int times = 5;
int timeout = 200;
Retriable<T> retriable = new Retriable<T>() {
{@literal @}Override
public T retriableCall() throws NoSuchAlgorithmException {
return getSomeT();
}
};
T retrievedT = retriable.retryCallOnFail(times, timeout);
This will retry the retriable
up to five times, with a pause of 200 milliseconds.Constructor and Description |
---|
Retriable() |
Modifier and Type | Method and Description |
---|---|
abstract T |
retriableCall()
A method which contains a retriable call.
|
T |
retryCallOnFail(int times,
long timeout)
Calls the
retriableCall() ('the call') up to times times and returns the result. |
protected void |
waitTimeout(long timeout)
Waits for specified number of milliseconds.
|
public abstract T retriableCall() throws NoSuchAlgorithmException
NoSuchAlgorithmException
as it is meant to wrap calls from
com.intuit.wasabi.authentication.impl.AuthenticationHelpers
s, which can throw these.NoSuchAlgorithmException
- if the method used in this call throws such an exception.protected void waitTimeout(long timeout) throws RetriableException
timeout
- sleep time in milliseconds.RetriableException
- when sleep is interruptedpublic T retryCallOnFail(int times, long timeout) throws RetriableException
retriableCall()
('the call') up to times
times and returns the result.
If the call was successful, this method returns.
If the call was not successful due to a missing implementation (throws NoSuchAlgorithmException
),
this method throws a RetriableException
.
If the call was not successful due to an UnknownHostException
and the number of trials does
not exceed times
, this method retries the call after sleeping for timeout
milliseconds.
If the call was not successful and/or the number of trials is exceeded, this method throws a
RetriableException
.times
- the number of times this method should be calledtimeout
- the timeout in millisecondsretriableCall()
RetriableException
- if retriableCall()
throws or the maximum number of trials was reachedCopyright © 2016. All rights reserved.