Package io.mochaapi.client
Class BasicRetry
java.lang.Object
io.mochaapi.client.BasicRetry
Simple retry configuration for failed requests.
Provides basic retry functionality with fixed delay.
Example usage:
BasicRetry retry = new BasicRetry(3, Duration.ofSeconds(1));
- Since:
- 1.0.0
-
Constructor Summary
ConstructorsConstructorDescriptionBasicRetry(int maxAttempts, Duration delay) Creates a new BasicRetry configuration. -
Method Summary
Modifier and TypeMethodDescriptionstatic BasicRetryCreates a BasicRetry with 2 attempts and 2-second delay.static BasicRetryfast()Creates a BasicRetry with 5 attempts and 500ms delay.getDelay()Returns the delay between retry attempts.intReturns the maximum number of attempts.booleanshouldRetry(int attemptNumber) Determines if a request should be retried based on the attempt number.static BasicRetrystandard()Creates a BasicRetry with 3 attempts and 1-second delay.toString()
-
Constructor Details
-
BasicRetry
Creates a new BasicRetry configuration.- Parameters:
maxAttempts- maximum number of attempts (including initial attempt)delay- delay between retry attempts- Throws:
IllegalArgumentException- if maxAttempts is less than 1 or delay is negative
-
-
Method Details
-
getMaxAttempts
public int getMaxAttempts()Returns the maximum number of attempts.- Returns:
- maximum attempts
-
getDelay
Returns the delay between retry attempts.- Returns:
- delay duration
-
shouldRetry
public boolean shouldRetry(int attemptNumber) Determines if a request should be retried based on the attempt number.- Parameters:
attemptNumber- current attempt number (1-based)- Returns:
- true if should retry
-
standard
Creates a BasicRetry with 3 attempts and 1-second delay.- Returns:
- standard retry configuration
-
fast
Creates a BasicRetry with 5 attempts and 500ms delay.- Returns:
- fast retry configuration
-
conservative
Creates a BasicRetry with 2 attempts and 2-second delay.- Returns:
- conservative retry configuration
-
toString
-