ru.dezhik.sms.sender.NetworkErrorRetryPolicy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sms-sender Show documentation
Show all versions of sms-sender Show documentation
Library for sending SMS via sms.ru gateway
package ru.dezhik.sms.sender;
import java.util.concurrent.TimeUnit;
import ru.dezhik.sms.sender.api.ApiRequest;
import ru.dezhik.sms.sender.api.InvocationStatus;
import ru.dezhik.sms.sender.api.ApiResponse;
/**
* @author ilya.dezhin
*/
public class NetworkErrorRetryPolicy implements RetryPolicy {
private final int maxExecutionAttempts;
private final long delayMs;
public NetworkErrorRetryPolicy() {
this(3, TimeUnit.SECONDS.toMillis(2));
}
public NetworkErrorRetryPolicy(int maxAttempts, long delayMs) {
this.maxExecutionAttempts = maxAttempts;
this.delayMs = delayMs;
}
@Override
public boolean shouldRetry(Req request, Resp response) {
return request.getStatus() == InvocationStatus.NETWORK_ERROR
&& request.getExecutionAttempt() < maxExecutionAttempts;
}
@Override
public long getDelayDurationMs() {
return delayMs;
}
}