Class RetryableOperationUtil

java.lang.Object
com.broadleafcommerce.search.util.RetryableOperationUtil

public class RetryableOperationUtil extends Object
Component to allow for retry-able operations. Often, when connecting to Solr or ZooKeeper, it may be required to retry operations due to network glitches, etc. Rather than failing a long-running process when something goes wrong, this allows us opportunities to retry these operations.
Author:
Kelly Tisdell (ktisdell)
  • Constructor Details

    • RetryableOperationUtil

      public RetryableOperationUtil()
  • 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 - Functional interface representing any operation; typically a lambda.
      Returns:
      null or the result of the operation
      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. Max wait time, assuming no successful iterations, will be 1500 milliseconds (100 + 200 + 300 + 400 + 500). This will never retry for an InterruptedException.
      Parameters:
      operation - Functional interface representing any operation; typically a lambda.
      noRetriesForException - Indicates a list of exceptions for which retries should not occur.
      Returns:
      null or the result of the operation
      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 - Functional interface representing any operation; typically a lambda.
      retries - Number of retries that should be attempted if an exception is thrown.
      waitTime - The time to wait between retries.
      isWaitTimesAdditive - Indicates if the wait time should be increased by the previous wait time on each try
      noRetriesForException - Indicates a list of exceptions for which retries should not occur.
      Returns:
      null or the result of the operation
      Throws:
      Exception