Package com.google.cloud.tools.jib.cache
Class Retry<E extends java.lang.Exception>
- java.lang.Object
-
- com.google.cloud.tools.jib.cache.Retry<E>
-
- Type Parameters:
E
- the class of exceptions that may be thrown
public class Retry<E extends java.lang.Exception> extends java.lang.Object
Retries an action until it succeeds, or has retried too often and failed. By default the action will be run up to 5 times. The action is deemed successful if it runs to completion without throwing an exception, and returns true.- Exceptions are caught and, if deemed
retryable
then the action will be re-attempted. By default, any exception is considered retryable. - The retry instance can be configured to
sleep between retries
. - The maximum retry count
is configurable
(5 times by default).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Retry.Action<E extends java.lang.Exception>
A runnable action that may throw an exception of typeE
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <E extends java.lang.Exception>
Retry<E>action(Retry.Action<E> action)
Create a retryable action.Retry<E>
maximumRetries(int maximumRetries)
Configure the maximum number of retries.Retry<E>
retryOnException(java.util.function.Predicate<java.lang.Exception> retryOnException)
Provide a predicate to determine if a thrown exception can be retried.boolean
run()
Run the action until it runs successfully, to amaximum number of retries
(default: 5).Retry<E>
sleep(long duration, java.util.concurrent.TimeUnit unit)
Set the sleep time between retries.
-
-
-
Method Detail
-
action
public static <E extends java.lang.Exception> Retry<E> action(Retry.Action<E> action)
Create a retryable action.- Type Parameters:
E
- the class of exceptions that may be thrown- Parameters:
action
- the action to be run- Returns:
- the instance
-
maximumRetries
public Retry<E> maximumRetries(int maximumRetries)
Configure the maximum number of retries.- Parameters:
maximumRetries
- the number of retries, must be zero or more- Returns:
- this Retry instance
-
retryOnException
public Retry<E> retryOnException(java.util.function.Predicate<java.lang.Exception> retryOnException)
Provide a predicate to determine if a thrown exception can be retried.- Parameters:
retryOnException
- determine if provided exception is retryable.- Returns:
- the instance for further configuration
-
sleep
public Retry<E> sleep(long duration, java.util.concurrent.TimeUnit unit)
Set the sleep time between retries.- Parameters:
duration
- the time to sleepunit
- the unit of time of duration- Returns:
- the instance for further configuration
-
run
public boolean run() throws E extends java.lang.Exception
Run the action until it runs successfully, to amaximum number of retries
(default: 5). If an exception occurs then the action will be retried providingthe exception is retryable
.
-
-