Class SimpleRetryPolicy

  • All Implemented Interfaces:
    RetryPolicy, Supplier<RetryPolicy>

    public final class SimpleRetryPolicy
    extends Object
    implements RetryPolicy
    A default retry policy implementation with ScheduledExecutorService. Following attributes can be configured:
    • number of retries (excluding the first invocation)
    • delay between the invocations
    • a delay multiplication factor
    • a timeout for the individual invocation
    • an overall timeout
    • an executor service
    • Method Detail

      • execute

        public <T> T execute​(Supplier<T> call)
                      throws ConfigException
        Description copied from interface: RetryPolicy
        Invokes the provided Supplier to read the source data and returns that data.

        The implementation of this method incorporates the retry logic.

        Specified by:
        execute in interface RetryPolicy
        Type Parameters:
        T - result type
        Parameters:
        call - supplier of T
        Returns:
        loaded data returned by the provided Supplier
        Throws:
        ConfigException
      • cancel

        public boolean cancel​(boolean mayInterruptIfRunning)
        Description copied from interface: RetryPolicy
        Cancels the current use of the retry policy.

        Implementations should correctly handle three cases:

        1. cancel invoked when no invocation of execute is in progress,
        2. cancel invoked when an invocation of execute is active but no attempted load is actually in progress (e.g., a prior attempt failed and the retry policy is waiting for some time to pass before trying again), and
        3. cancel invoked while a load attempt is in progress.
        Specified by:
        cancel in interface RetryPolicy
        Parameters:
        mayInterruptIfRunning - whether an in-progress load attempt should be interrupted
        Returns:
        false if the task could not be canceled, typically because it has already completed; true otherwise
      • retries

        public int retries()
        Number of retries.
        Returns:
        retries
      • delay

        public Duration delay()
        Delay between retries.
        Returns:
        delay
      • delayFactor

        public double delayFactor()
        Delay multiplication factor.
        Returns:
        delay factor
      • callTimeout

        public Duration callTimeout()
        Timeout of the call.
        Returns:
        call timeout
      • overallTimeout

        public Duration overallTimeout()
        Overall timeout.
        Returns:
        overall timeout