Class RetryStorageOperation
java.lang.Object
com.google.jenkins.plugins.storage.util.RetryStorageOperation
A class to facilitate retries on storage operations.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
An operation to be retriedstatic interface
An action that may fail because of expired credentials. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <Ex extends Throwable>
voidstatic <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 Details
-
MAX_REMOTE_CREDENTIAL_EXPIRED_RETRIES
public static final int MAX_REMOTE_CREDENTIAL_EXPIRED_RETRIES- See Also:
-
-
Constructor Details
-
RetryStorageOperation
public RetryStorageOperation()
-
-
Method Details
-
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 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
.
-
performRequestWithReinitCredentials
public static <Ex extends Throwable> void performRequestWithReinitCredentials(RetryStorageOperation.RepeatOperation<Ex> a) throws IOException, InterruptedException, com.google.jenkins.plugins.util.ExecutorException, Ex - Throws:
IOException
InterruptedException
com.google.jenkins.plugins.util.ExecutorException
Ex extends Throwable
-