public class 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.
Constructors
CloudStorageRetryHandler(CloudStorageConfiguration config)
public CloudStorageRetryHandler(CloudStorageConfiguration config)
Create a CloudStorageRetryHandler with the maximum retries and reopens set to the same value.
Parameter | |
---|---|
Name | Description |
config |
CloudStorageConfiguration
|
CloudStorageRetryHandler(int maxRetriesAndReopens) (deprecated)
public CloudStorageRetryHandler(int maxRetriesAndReopens)
Deprecated. use CloudStorageRetryHandler(CloudStorageConfiguration) instead.
Create a CloudStorageRetryHandler with the maximum retries and reopens set to the same value.
Parameter | |
---|---|
Name | Description |
maxRetriesAndReopens |
int value for both maxRetries and maxReopens |
CloudStorageRetryHandler(int maxRetries, int maxReopens) (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 | |
---|---|
Name | Description |
maxRetries |
int maximum number of retries |
maxReopens |
int maximum number of reopens |
CloudStorageRetryHandler(int maxRetries, int maxReopens, CloudStorageConfiguration config)
public CloudStorageRetryHandler(int maxRetries, int maxReopens, CloudStorageConfiguration config)
Create a CloudStorageRetryHandler with the maximum retries and reopens set to different values.
Parameters | |
---|---|
Name | Description |
maxRetries |
int maximum number of retries |
maxReopens |
int maximum number of reopens (overrides what's in the config) |
config |
CloudStorageConfiguration http codes we'll retry on, and exceptions we'll reopen on. |
Methods
handleStorageException(StorageException exs)
public boolean handleStorageException(StorageException exs)
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.
Parameter | |
---|---|
Name | Description |
exs |
com.google.cloud.storage.StorageException caught StorageException |
Returns | |
---|---|
Type | Description |
boolean |
True if you need to reopen and then try again. False if you can just try again. |
Exceptions | |
---|---|
Type | Description |
com.google.cloud.storage.StorageException |
if the exception is not retryable, or if you ran out of retries. |
reopens()
public int reopens()
Returns | |
---|---|
Type | Description |
int |
number of reopens we've performed |
retries()
public int retries()
Returns | |
---|---|
Type | Description |
int |
number of retries we've performed |