Class DefaultRetryStrategy<T>

java.lang.Object
de.dlr.proseo.storagemgr.model.DefaultRetryStrategy<T>

public class DefaultRetryStrategy<T> extends Object
A retry strategy for executing atomic operations. The class provides a mechanism to retry a specified command multiple times until it succeeds or reaches the configured maximum number of attempts.
Author:
Denys Chaykovskiy
  • Constructor Summary

    Constructors
    Constructor
    Description
    DefaultRetryStrategy(AtomicCommand<T> atomicCommand, int maxAttempts, long waitTime)
    The constructor initializes the retry strategy with the atomic command to be executed, the maximum number of attempts, and the wait time between each attempt.
  • Method Summary

    Modifier and Type
    Method
    Description
    Tries to execute the atomic command and returns its result if successful.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DefaultRetryStrategy

      public DefaultRetryStrategy(AtomicCommand<T> atomicCommand, int maxAttempts, long waitTime)
      The constructor initializes the retry strategy with the atomic command to be executed, the maximum number of attempts, and the wait time between each attempt.
      Parameters:
      atomicCommand - atomic command
      maxAttempts - maximal attempts
      waitTime - wait time between retries
  • Method Details

    • execute

      public T execute() throws IOException
      Tries to execute the atomic command and returns its result if successful. If the atomic command throws an IOException, the retry strategy catches and records it. It repeats the execution of the atomic command for a specified number of attempts, waiting for a certain time interval between each attempt. If the maximum number of attempts is reached without a successful execution, the retry strategy throws the recorded exception.
      Returns:
      string with result of strategy execution
      Throws:
      IOException - if atom command was not successful maxAttempts times