Class CloudStorageRetryHandler
java.lang.Object
com.google.cloud.storage.contrib.nio.CloudStorageRetryHandler
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 Summary
ConstructorsConstructorDescriptionCloudStorageRetryHandler(int maxRetriesAndReopens) Deprecated.use CloudStorageRetryHandler(CloudStorageConfiguration) instead.CloudStorageRetryHandler(int maxRetries, int maxReopens) Deprecated.use CloudStorageRetryHandler(CloudStorageConfiguration) instead.CloudStorageRetryHandler(int maxRetries, int maxReopens, CloudStorageConfiguration config) Create a CloudStorageRetryHandler with the maximum retries and reopens set to different values.Create a CloudStorageRetryHandler with the maximum retries and reopens set to the same value. -
Method Summary
Modifier and TypeMethodDescriptionbooleanhandleStorageException(com.google.cloud.storage.StorageException exs) Checks whether we should retry, reopen, or give up.intreopens()intretries()
-
Constructor Details
-
CloudStorageRetryHandler
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.use CloudStorageRetryHandler(CloudStorageConfiguration) instead.Create a CloudStorageRetryHandler with the maximum retries and reopens set to different values.- Parameters:
maxRetries- maximum number of retriesmaxReopens- maximum number of reopens
-
CloudStorageRetryHandler
Create a CloudStorageRetryHandler with the maximum retries and reopens set to the same value.- Parameters:
config- - configuration for reopens and retryable codes.
-
CloudStorageRetryHandler
Create a CloudStorageRetryHandler with the maximum retries and reopens set to different values.- Parameters:
maxRetries- maximum number of retriesmaxReopens- maximum number of reopens (overrides what's in the config)config- http codes we'll retry on, and exceptions we'll reopen on.
-
-
Method Details
-
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.
-