Class RetryStorageOperation
- java.lang.Object
-
- com.google.jenkins.plugins.storage.util.RetryStorageOperation
-
public class RetryStorageOperation extends Object
A class to facilitate retries on storage operations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
RetryStorageOperation.Operation
An operation to be retriedstatic interface
RetryStorageOperation.RepeatOperation<Ex extends Throwable>
An action that may fail because of expired credentials.
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_REMOTE_CREDENTIAL_EXPIRED_RETRIES
-
Constructor Summary
Constructors Constructor Description RetryStorageOperation()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <Ex extends Throwable>
voidperformRequestWithReinitCredentials(RetryStorageOperation.RepeatOperation<Ex> a)
static <Ex extends Throwable>
voidperformRequestWithReinitCredentials(RetryStorageOperation.RepeatOperation<Ex> a, int retries)
Keeps performing actions until credentials expire.static void
performRequestWithRetry(com.google.jenkins.plugins.util.Executor executor, RetryStorageOperation.Operation a, int attempts)
Perform the given operation retrying on error.
-
-
-
Field Detail
-
MAX_REMOTE_CREDENTIAL_EXPIRED_RETRIES
public static final int MAX_REMOTE_CREDENTIAL_EXPIRED_RETRIES
- See Also:
- Constant Field Values
-
-
Method Detail
-
performRequestWithRetry
public static void performRequestWithRetry(com.google.jenkins.plugins.util.Executor executor, RetryStorageOperation.Operation a, int attempts) throws IOException, InterruptedException, com.google.jenkins.plugins.util.ExecutorException
Perform the given operation retrying on error. The operation is retried if either IOException or InterruptedException occur. After the given number of retries, throws the last error received. Any other exceptions are passed through.- Parameters:
executor
- The executor to use for the operationa
- The operation to execute.attempts
- How many attempts to make. Must be at least 1.- Throws:
IOException
- If performing the operation threw an IOException.InterruptedException
- If performing the operation threw an InterruptedException.com.google.jenkins.plugins.util.ExecutorException
- If the executor threw an exception while performing the operation.
-
performRequestWithReinitCredentials
public static <Ex extends Throwable> void performRequestWithReinitCredentials(RetryStorageOperation.RepeatOperation<Ex> a, int retries) throws IOException, InterruptedException, com.google.jenkins.plugins.util.ExecutorException, Ex extends Throwable
Keeps performing actions until credentials expire. When they do, calls initCredentials() and continues. It relies on the RepeatOperation to keep any state required to start where it left off.HttpResponseException with the code Unauthorized is caught. Any other exceptions are passed through.
- Type Parameters:
Ex
- An action-specific exception that might be throwns.- Parameters:
a
- Operation to executeretries
- How many times to attempt to refresh credentials if there is no progress. (Every time an action successfully completes, the retry budget is reset)- Throws:
IOException
- If performing the operation threw an IOException.InterruptedException
- If performing the operation threw an InterruptedException.com.google.jenkins.plugins.util.ExecutorException
- If the executor threw an exception while performing the operation.Ex
- Custom exception thrown by theRetryStorageOperation.Operation
.Ex extends Throwable
-
performRequestWithReinitCredentials
public static <Ex extends Throwable> void performRequestWithReinitCredentials(RetryStorageOperation.RepeatOperation<Ex> a) throws IOException, InterruptedException, com.google.jenkins.plugins.util.ExecutorException, Ex extends Throwable
- Throws:
IOException
InterruptedException
com.google.jenkins.plugins.util.ExecutorException
Ex extends Throwable
-
-