Class GenericOperationUtil

java.lang.Object
org.broadleafcommerce.common.util.GenericOperationUtil

public class GenericOperationUtil extends Object
Provides a mechanism to allow for retriable logic.
Author:
Kelly Tisdell
  • Constructor Details

    • GenericOperationUtil

      public GenericOperationUtil()
  • Method Details

    • executeRetryableOperation

      public static <R> R executeRetryableOperation(GenericOperation<R> operation) throws Exception
      Executes the provided operation up to 5 times if there are exceptions, waiting an additive 100 ms between tries.

      Total wait time, assuming no successful iterations, will be 1500 milliseconds (100 + 200 + 300 + 400 + 500).

      This will never retry for an InterruptedException.

      Parameters:
      operation -
      Returns:
      Throws:
      Exception
    • executeRetryableOperation

      public static <R> R executeRetryableOperation(GenericOperation<R> operation, Class<? extends Exception>[] noRetriesForException) throws Exception
      Executes the provided operation up to 5 times if there are exceptions, waiting an additive 100 ms between tries.

      Total wait time, assuming no successful iterations, will be 1500 milliseconds (100 + 200 + 300 + 400 + 500).

      This will never retry for an InterruptedException.

      Parameters:
      operation -
      noRetriesForException -
      Returns:
      Throws:
      Exception
    • executeRetryableOperation

      public static <R> R executeRetryableOperation(GenericOperation<R> operation, int retries, long waitTime, boolean isWaitTimesAdditive, Class<? extends Exception>[] noRetriesForException) throws Exception
      Executes the provided operation up to as many times as the retries argument. The method will return upon successful completion. However, it will retry up to retries times. The wait time is the amount of time that this method will wait between tries. If isWaitTimesAdditive, then the waitTime parameter will be multiplied by the current retry iteration each time. Otherwise, the waitTime will not change between tries.

      If retries == 5, waitTime == 100, and isWaitTimesAdditive == false, then the total wait time, assuming no successful iterations, will be 500 milliseconds (100 + 100 + 100 + 100 + 100). If retries == 5, waitTime == 100, and isWaitTimesAdditive == true, then the total wait time, assuming no successful iterations, will be 1500 milliseconds (100 + 200 + 300 + 400 + 500).

      This will never retry for an InterruptedException.

      Parameters:
      operation -
      retries -
      waitTime -
      isWaitTimesAdditive -
      noRetriesForException -
      Returns:
      Throws:
      Exception