Class CloudStorageRetryHandler (0.124.21)

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.

Inheritance

java.lang.Object > CloudStorageRetryHandler

Constructors

CloudStorageRetryHandler(CloudStorageConfiguration config)

public CloudStorageRetryHandler(CloudStorageConfiguration config)

Create a CloudStorageRetryHandler with the maximum retries and reopens set to the same value.

Parameter
NameDescription
configCloudStorageConfiguration
  • configuration for reopens and retryable codes.

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
NameDescription
maxRetriesAndReopensint

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
NameDescription
maxRetriesint

maximum number of retries

maxReopensint

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
NameDescription
maxRetriesint

maximum number of retries

maxReopensint

maximum number of reopens (overrides what's in the config)

configCloudStorageConfiguration

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
NameDescription
exscom.google.cloud.storage.StorageException

caught StorageException

Returns
TypeDescription
boolean

True if you need to reopen and then try again. False if you can just try again.

Exceptions
TypeDescription
com.google.cloud.storage.StorageException

if the exception is not retryable, or if you ran out of retries.

reopens()

public int reopens()
Returns
TypeDescription
int

number of reopens we've performed

retries()

public int retries()
Returns
TypeDescription
int

number of retries we've performed