Class CloudStorageRetryHandler


  • public class CloudStorageRetryHandler
    extends Object
    Simple counter class to keep track of retry and reopen attempts when StorageExceptions are encountered. Handles sleeping between retry/reopen attempts, as well as throwing an exception when all retries/reopens are exhausted.
    • Constructor Detail

      • CloudStorageRetryHandler

        @Deprecated
        public CloudStorageRetryHandler​(int maxRetriesAndReopens)
        Deprecated.
        use CloudStorageRetryHandler(CloudStorageConfiguration) instead.
        Create a CloudStorageRetryHandler with the maximum retries and reopens set to the same value.
        Parameters:
        maxRetriesAndReopens - value for both maxRetries and maxReopens
      • CloudStorageRetryHandler

        @Deprecated
        public CloudStorageRetryHandler​(int maxRetries,
                                        int maxReopens)
        Deprecated.
        use CloudStorageRetryHandler(CloudStorageConfiguration) instead.
        Create a CloudStorageRetryHandler with the maximum retries and reopens set to different values.
        Parameters:
        maxRetries - maximum number of retries
        maxReopens - maximum number of reopens
      • CloudStorageRetryHandler

        public CloudStorageRetryHandler​(CloudStorageConfiguration config)
        Create a CloudStorageRetryHandler with the maximum retries and reopens set to the same value.
        Parameters:
        config - - configuration for reopens and retryable codes.
      • CloudStorageRetryHandler

        public CloudStorageRetryHandler​(int maxRetries,
                                        int maxReopens,
                                        CloudStorageConfiguration config)
        Create a CloudStorageRetryHandler with the maximum retries and reopens set to different values.
        Parameters:
        maxRetries - maximum number of retries
        maxReopens - maximum number of reopens (overrides what's in the config)
        config - http codes we'll retry on, and exceptions we'll reopen on.
    • Method Detail

      • retries

        public int retries()
        Returns:
        number of retries we've performed
      • reopens

        public int reopens()
        Returns:
        number of reopens we've performed
      • handleStorageException

        public boolean handleStorageException​(com.google.cloud.storage.StorageException exs)
                                       throws com.google.cloud.storage.StorageException
        Checks whether we should retry, reopen, or give up.

        In the latter case it throws an exception (this includes the scenario where we exhausted the retry count).

        Otherwise, it sleeps for a bit and returns whether we should reopen. The sleep time is dependent on the retry number.

        Parameters:
        exs - caught StorageException
        Returns:
        True if you need to reopen and then try again. False if you can just try again.
        Throws:
        com.google.cloud.storage.StorageException - if the exception is not retryable, or if you ran out of retries.