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

com.crabshue.commons.retryable.RetryPolicyBuilder Maven / Gradle / Ivy

package com.crabshue.commons.retryable;

import java.util.concurrent.TimeUnit;

import lombok.NonNull;
import net.jodah.failsafe.RetryPolicy;

/**
 * {@link RetryPolicy} builder.
 */
public class RetryPolicyBuilder {

    /**
     * Build a {@link RetryPolicy} with {@link RetryOptions}.
     *
     * @param retryOptions the retry options.
     * @return the retry policy.
     */
    public static RetryPolicy newRetryPolicy(@NonNull final RetryOptions retryOptions) {

        return new RetryPolicy()
            .retryOn(Exception.class)
            .withDelay(retryOptions.getSleepBetweenRetriesInMilliseconds(), TimeUnit.MILLISECONDS)
            .withMaxRetries(retryOptions.getMaximumNumberOfRetries());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy