Package org.apache.pinot.spi.utils.retry
Class BaseRetryPolicy
- java.lang.Object
-
- org.apache.pinot.spi.utils.retry.BaseRetryPolicy
-
- All Implemented Interfaces:
RetryPolicy
- Direct Known Subclasses:
ExponentialBackoffRetryPolicy,FixedDelayRetryPolicy,NoDelayRetryPolicy,RandomDelayRetryPolicy
public abstract class BaseRetryPolicy extends Object implements RetryPolicy
TheBaseRetryPolicyis the base class for all retry policies. To implement a new retry policy, extends this class and implements the methodgetDelayMs(int).NOTE: All the retry policies should be stateless so that they can be cached and reused.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBaseRetryPolicy(int maxNumAttempts)
-
Method Summary
Modifier and Type Method Description voidattempt(Callable<Boolean> operation)Attempts to do the operation until it succeeds, aborting if an exception is thrown by the operation or number of attempts exhausted.protected abstract longgetDelayMs(int currentAttempt)Gets the delay in milliseconds before the next attempt.
-
-
-
Method Detail
-
getDelayMs
protected abstract long getDelayMs(int currentAttempt)
Gets the delay in milliseconds before the next attempt.- Parameters:
currentAttempt- Current attempt number- Returns:
- Delay in milliseconds
-
attempt
public void attempt(Callable<Boolean> operation) throws AttemptsExceededException, RetriableOperationException
Description copied from interface:RetryPolicyAttempts to do the operation until it succeeds, aborting if an exception is thrown by the operation or number of attempts exhausted.- Specified by:
attemptin interfaceRetryPolicy- Parameters:
operation- The operation to attempt, which returns true on success and false on failure.- Throws:
AttemptsExceededExceptionRetriableOperationException
-
-