Package org.apache.solr.common.util

# Class RetryUtil

java.lang.Object
org.apache.solr.common.util.RetryUtil

public class RetryUtil extends Object
Utility class for retrying operations with various strategies.

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static interface`
`RetryUtil.BooleanRetryCmd`
Interface for commands that return a boolean result indicating success or failure.
`static interface`
`RetryUtil.RetryCmd`
Interface for commands that can be retried and may throw exceptions.

## Constructor Summary

Constructors
Constructor
Description
`RetryUtil()`

## Method Summary

Modifier and Type
Method
Description
`static void`
`retryOnBoolean(long timeoutms, long intervalms, RetryUtil.BooleanRetryCmd cmd)`
Retries a command until it returns `true` or the timeout is reached.
`static void`
`retryOnException(Class<? extends Exception> clazz, long timeoutms, long intervalms, RetryUtil.RetryCmd cmd)`
Retries a command when a specific exception type occurs, until successful or timeout is reached.
`static void`
`retryOnException(Set<Class<? extends Exception>> classes, long timeoutms, long intervalms, RetryUtil.RetryCmd cmd)`
Retries a command when any of the specified exception types occur, until successful or timeout is reached.
`static void`
`retryUntil(String errorMessage, int retries, long pauseTime, TimeUnit pauseUnit, RetryUtil.BooleanRetryCmd cmd)`
Retries a command until it returns `true` or the maximum number of retries is reached.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### RetryUtil

public RetryUtil()

## Method Details

### retryOnException

public static void retryOnException(Class<? extends Exception> clazz, long timeoutms, long intervalms, RetryUtil.RetryCmd cmd) throws Exception
Retries a command when a specific exception type occurs, until successful or timeout is reached.

This is a convenience method that delegates to `retryOnException(Set, long, long, RetryCmd)` with a singleton set containing the specified exception class.

Parameters:
  `clazz` - the exception class to retry on
  `timeoutms` - maximum time to retry in milliseconds
  `intervalms` - wait interval between retries in milliseconds
  `cmd` - the command to execute
Throws:
  `Exception` - if the command fails with a different exception, or if timeout is reached
  `InterruptedException` - if the thread is interrupted while sleeping between retries

### retryOnException

public static void retryOnException(Set<Class<? extends Exception>> classes, long timeoutms, long intervalms, RetryUtil.RetryCmd cmd) throws Exception
Retries a command when any of the specified exception types occur, until successful or timeout is reached.

The command is executed repeatedly until it succeeds (completes without throwing an exception) or the timeout is reached. If an exception matching one of the specified classes is thrown and there is time remaining, the method will sleep for `intervalms` milliseconds before retrying. If a different exception is thrown, or if the timeout is reached, the exception is rethrown.

Parameters:
  `classes` - set of exception classes to retry on
  `timeoutms` - maximum time to retry in milliseconds
  `intervalms` - wait interval between retries in milliseconds
  `cmd` - the command to execute
Throws:
  `Exception` - if the command fails with an exception not in the specified set, or if timeout is reached
  `InterruptedException` - if the thread is interrupted while sleeping between retries

### retryUntil

public static void retryUntil(String errorMessage, int retries, long pauseTime, TimeUnit pauseUnit, RetryUtil.BooleanRetryCmd cmd) throws InterruptedException
Retries a command until it returns `true` or the maximum number of retries is reached.

The command is executed up to `retries` times. After each failed attempt (when the command returns `false`), the method pauses for the specified duration before retrying. If all retries are exhausted without success, a `SolrException` is thrown with the provided error message.

Parameters:
  `errorMessage` - the error message to use if all retries are exhausted
  `retries` - maximum number of retry attempts
  `pauseTime` - duration to pause between retries
  `pauseUnit` - time unit for the pause duration
  `cmd` - the command to execute
Throws:
  `InterruptedException` - if the thread is interrupted while sleeping between retries
  `SolrException` - if all retries are exhausted without success

### retryOnBoolean

public static void retryOnBoolean(long timeoutms, long intervalms, RetryUtil.BooleanRetryCmd cmd)
Retries a command until it returns `true` or the timeout is reached.

The command is executed repeatedly until it returns `true` or the timeout expires. If the command returns `false` and there is time remaining, the method sleeps for `intervalms` milliseconds before retrying. If the timeout is reached before the command succeeds, a `SolrException` is thrown.

Parameters:
  `timeoutms` - maximum time to retry in milliseconds
  `intervalms` - wait interval between retries in milliseconds
  `cmd` - the command to execute
Throws:
  `SolrException` - if no success within timeout