com.bazaarvoice.ostrich.retry.SleepingRetry Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ostrich-core Show documentation
Show all versions of ostrich-core Show documentation
Core classes that form Ostrich
package com.bazaarvoice.ostrich.retry;
import com.bazaarvoice.ostrich.RetryPolicy;
import static com.google.common.base.Preconditions.checkArgument;
public abstract class SleepingRetry implements RetryPolicy {
private final int _maxNumAttempts;
protected SleepingRetry(int maxNumAttempts) {
checkArgument(maxNumAttempts >= 0);
_maxNumAttempts = maxNumAttempts;
}
@Override
public boolean allowRetry(int numAttempts, long elapsedTimeMs) {
checkArgument(numAttempts >= 1);
if (numAttempts >= _maxNumAttempts) {
return false;
}
try {
Thread.sleep(getSleepTimeMs(numAttempts, elapsedTimeMs));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return false;
}
return true;
}
protected abstract long getSleepTimeMs(int numAttempts, long elapsedTimeMs);
}