Class RetryStorageOperation


  • public class RetryStorageOperation
    extends Object
    A class to facilitate retries on storage operations.
    • Field Detail

      • MAX_REMOTE_CREDENTIAL_EXPIRED_RETRIES

        public static final int MAX_REMOTE_CREDENTIAL_EXPIRED_RETRIES
        See Also:
        Constant Field Values
    • Constructor Detail

      • RetryStorageOperation

        public RetryStorageOperation()
    • 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 operation
        a - 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 execute
        retries - 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 the RetryStorageOperation.Operation.
        Ex extends Throwable