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

org.zodiac.okhttp.RetryPolicy Maven / Gradle / Ivy

The newest version!
package org.zodiac.okhttp;

import org.springframework.retry.policy.SimpleRetryPolicy;

import javax.annotation.Nullable;
import java.util.function.Predicate;

/**
 * 重试策略。
 *
 */
public class RetryPolicy {

    public static final RetryPolicy DEFAULT = new RetryPolicy();

    private final int maxAttempts;
    private final long sleepMillis;
    @Nullable
    private final Predicate respPredicate;

    public RetryPolicy() {
        this(null);
    }

    public RetryPolicy(int maxAttempts, long sleepMillis) {
        this(maxAttempts, sleepMillis, null);
    }

    public RetryPolicy(@Nullable Predicate respPredicate) {
        this(SimpleRetryPolicy.DEFAULT_MAX_ATTEMPTS, 0L, respPredicate);
    }

    public RetryPolicy(int maxAttempts, long sleepMillis, @Nullable Predicate respPredicate) {
        this.maxAttempts = maxAttempts;
        this.sleepMillis = sleepMillis;
        this.respPredicate = respPredicate;
    }

    public int getMaxAttempts() {
        return maxAttempts;
    }

    public long getSleepMillis() {
        return sleepMillis;
    }

    public Predicate getRespPredicate() {
        return respPredicate;
    }

    @Override
    public String toString() {
        return "RetryPolicy [maxAttempts=" + maxAttempts + ", sleepMillis=" + sleepMillis + ", respPredicate="
            + respPredicate + "]";
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy