Class GenericOperationUtil
- Author:
- Kelly Tisdell
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <R> R
executeRetryableOperation
(GenericOperation<R> operation) Executes the provided operation up to 5 times if there are exceptions, waiting an additive 100 ms between tries.static <R> R
executeRetryableOperation
(GenericOperation<R> operation, int retries, long waitTime, boolean isWaitTimesAdditive, Class<? extends Exception>[] noRetriesForException) Executes the provided operation up to as many times as the retries argument.static <R> R
executeRetryableOperation
(GenericOperation<R> operation, Class<? extends Exception>[] noRetriesForException) Executes the provided operation up to 5 times if there are exceptions, waiting an additive 100 ms between tries.
-
Constructor Details
-
GenericOperationUtil
public GenericOperationUtil()
-
-
Method Details
-
executeRetryableOperation
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 toretries
times. The wait time is the amount of time that this method will wait between tries. IfisWaitTimesAdditive
, 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
-