
com.github.rbuck.retry.Incremental Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-retry Show documentation
Show all versions of java-retry Show documentation
Lets developers make their applications more resilient by adding robust
transient fault handling logic. Transient faults are errors that occur
because of some temporary condition such as network connectivity issues
or service unavailability. Typically, if you retry the operation that
resulted in a transient error a short time later, you find that the
error has disappeared.
package com.github.rbuck.retry;
import static com.github.rbuck.retry.RetryState.RetryStateCommon.addDelay;
/**
* Implementation for an incremental retry strategy with fixed initial and
* incremental wait times.
*
* @author Robert Buck ([email protected])
*/
public class Incremental implements RetryStrategy {
private final int maxRetries;
private final long initialInterval;
private final long incrementalInterval;
public Incremental(int maxRetries, long initialInterval, long incrementalInterval) {
this.maxRetries = maxRetries;
this.initialInterval = initialInterval;
this.incrementalInterval = incrementalInterval;
}
@Override
public RetryState getRetryState() {
return new RetryState() {
private int retryCount;
@Override
public void delayRetry() {
addDelay(getRetryDelay());
}
@Override
public boolean hasRetries() {
if (retryCount < maxRetries) {
retryCount++;
return true;
}
return false;
}
@Override
public int getRetryCount() {
return retryCount;
}
@Override
public long getRetryDelay() {
return initialInterval + incrementalInterval * retryCount;
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy