public class Retry<R> {
private static int MAX_RETRY_COUNT = 3;
private HystrixCommand<R> command;
public HystrixCommandRetryExecutor(HystrixCommand<R> command) {
this.command = command;
}
public R execute() {
R result = null;
for (int currentRequestCount = 1; currentRequestCount <= MAX_RETRY_COUNT; currentRequestCount++) {
try {
int retryAttempt = currentRequestCount - 1;
long sleepTime = 50 * retryAttempt;
TimeUnit.MILLISECONDS.sleep(sleepTime);
result = command.execute();
break;
} catch (Exception e) {
LOG.debug("Command=" + command, e);
}
}
return result;
}
}