All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.dezhik.sms.sender.NetworkErrorRetryPolicy Maven / Gradle / Ivy

There is a newer version: 0.1.3
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy