Package oracle.nosql.driver

# Interface RetryHandler

All Known Implementing Classes:
  `DefaultRetryHandler`

public interface RetryHandler
RetryHandler is called by the request handling system when a `RetryableException` is thrown. It controls the number of retries as well as frequency of retries using a delaying algorithm. A default RetryHandler is always configured on a `NoSQLHandle` instance and can be controlled or overridden using `NoSQLHandleConfig.setRetryHandler(oracle.nosql.driver.RetryHandler)` and `NoSQLHandleConfig.configureDefaultRetryHandler(int, int)`

It is not recommended that applications rely on a RetryHandler for regulating provisioned throughput. It is best to add rate limiting to the application based on a table's capacity and access patterns to avoid throttling exceptions: see `NoSQLHandleConfig.setRateLimitingEnabled(boolean)`.

Instances of this interface must be immutable so they can be shared among threads.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `delay(Request request, int numRetries, RetryableException re)`
  This method is called when a `RetryableException` is thrown and it is determined that the request will be retried based on the return value of `doRetry(oracle.nosql.driver.ops.Request, int, oracle.nosql.driver.RetryableException)`.
  `boolean`
  `doRetry(Request request, int numRetries, RetryableException re)`
  This method is called when a `RetryableException` is thrown and determines whether to perform a retry or not based on the parameters.
  `int`
  `getNumRetries()`
  Returns the number of retries that this handler instance will allow before the exception is thrown to the application.

- ## Method Details

  - ### getNumRetries

    int getNumRetries()
    Returns the number of retries that this handler instance will allow before the exception is thrown to the application.
    Returns:
      the max number of retries

  - ### doRetry

    boolean doRetry(Request request, int numRetries, RetryableException re)
    This method is called when a `RetryableException` is thrown and determines whether to perform a retry or not based on the parameters.
    Parameters:
      `request` - the Request that has triggered the exception
      `numRetries` - the number of retries that have occurred for the operation
      `re` - the exception that was thrown
    Returns:
      true if the operation should be retried, false if not, causing the exception to be thrown to the application.

  - ### delay

    void delay(Request request, int numRetries, RetryableException re)
    This method is called when a `RetryableException` is thrown and it is determined that the request will be retried based on the return value of `doRetry(oracle.nosql.driver.ops.Request, int, oracle.nosql.driver.RetryableException)`. It provides a delay between retries. Most implementations will sleep for some period of time. The method should not return until the desired delay period has passed. Implementations should not busy-wait in a tight loop.
    Parameters:
      `request` - the Request that has triggered the exception
      `numRetries` - the number of retries that have occurred for the operation
      `re` - the exception that was thrown