Class RetryStrategy.LinearRetryStrategy

java.lang.Object
org.sterl.spring.persistent_tasks.api.RetryStrategy.LinearRetryStrategy
All Implemented Interfaces:
RetryStrategy
Enclosing interface:
RetryStrategy

public static class RetryStrategy.LinearRetryStrategy extends Object implements RetryStrategy
A retry strategy that determines the next retry time by adding a fixed offset and the execution count to the current time in the specified temporal unit.

This strategy can be used to create retry intervals that increase linearly with the number of attempts, providing a predictable delay pattern.

Example: If offset = 5, unit = ChronoUnit.SECONDS, and executionCount = 3, the next retry will be scheduled after 5 + 3 = 8 seconds from the current time.

Note: The retry attempts will stop once the maximum execution count (maxExecutionCount) is reached.

Author:
Your Name
  • Constructor Details

    • LinearRetryStrategy

      public LinearRetryStrategy()
  • Method Details

    • shouldRetry

      public boolean shouldRetry(int executionCount, @Nullable Exception error)
      Description copied from interface: RetryStrategy
      Determines whether a retry should be attempted based on the current execution count and the provided exception. (optional)
      Specified by:
      shouldRetry in interface RetryStrategy
      Parameters:
      executionCount - The number of attempts already made.
      error - The exception that triggered the retry.
      Returns:
      true if the current execution count is less than the maximum execution count; false otherwise.
    • retryAt

      public OffsetDateTime retryAt(int executionCount, @Nullable Exception error)
      Description copied from interface: RetryStrategy
      Calculates the time of the next retry attempt based on the current execution count and the provided exception.
      Specified by:
      retryAt in interface RetryStrategy
      Parameters:
      executionCount - The number of attempts already made.
      error - The exception that triggered the retry.
      Returns:
      OffsetDateTime of the next execution, null for no retry.