Package net.jodah.lyra.config
Class RetryPolicy
java.lang.Object
net.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
net.jodah.lyra.config.RetryPolicy
public class RetryPolicy extends net.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
Policy that defines how retries should be performed.
-
Constructor Summary
Constructors Constructor Description RetryPolicy()
Creates a retry policy that retries forever. -
Method Summary
Modifier and Type Method Description boolean
allowsAttempts()
Returns whether the policy allows any attempts based on the configured maxAttempts and maxDuration.Duration
getInterval()
Returns the interval between attempts.int
getIntervalMultiplier()
Returns the interval multiplier for backoff attempts.int
getMaxAttempts()
Returns the max attempts.Duration
getMaxDuration()
Returns the max duration to perform attempts for.Duration
getMaxInterval()
Returns the max interval between backoff attempts.RetryPolicy
withBackoff(Duration interval, Duration maxInterval)
Sets theinterval
to pause for between attempts, exponentially backing of to themaxInterval
multiplying successive intervals by a factor of 2.RetryPolicy
withBackoff(Duration interval, Duration maxInterval, int intervalMultiplier)
Sets theinterval
to pause for between attempts, exponentially backing of to themaxInterval
multiplying successive intervals by theintervalMultiplier
.RetryPolicy
withInterval(Duration interval)
Sets theinterval
to pause for between attempts.RetryPolicy
withMaxAttempts(int maxAttempts)
Sets the max number of attempts to perform.RetryPolicy
withMaxDuration(Duration maxDuration)
Sets the max duration to perform attempts for.
-
Constructor Details
-
RetryPolicy
public RetryPolicy()Creates a retry policy that retries forever.
-
-
Method Details
-
allowsAttempts
public boolean allowsAttempts()Returns whether the policy allows any attempts based on the configured maxAttempts and maxDuration.- Overrides:
allowsAttempts
in classnet.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
-
getInterval
Returns the interval between attempts.- Overrides:
getInterval
in classnet.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
- See Also:
withInterval(Duration)
,withBackoff(Duration, Duration)
,withBackoff(Duration, Duration, int)
-
getIntervalMultiplier
public int getIntervalMultiplier()Returns the interval multiplier for backoff attempts.- Overrides:
getIntervalMultiplier
in classnet.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
- See Also:
withBackoff(Duration, Duration, int)
-
getMaxAttempts
public int getMaxAttempts()Returns the max attempts.- Overrides:
getMaxAttempts
in classnet.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
- See Also:
withMaxAttempts(int)
-
getMaxDuration
Returns the max duration to perform attempts for.- Overrides:
getMaxDuration
in classnet.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
- See Also:
withMaxDuration(Duration)
-
getMaxInterval
Returns the max interval between backoff attempts.- Overrides:
getMaxInterval
in classnet.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
- See Also:
withBackoff(Duration, Duration)
-
withBackoff
Sets theinterval
to pause for between attempts, exponentially backing of to themaxInterval
multiplying successive intervals by a factor of 2.- Overrides:
withBackoff
in classnet.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
- Throws:
java.lang.NullPointerException
- ifinterval
ormaxInterval
are nulljava.lang.IllegalArgumentException
- ifinterval
is <= 0 orinterval
is >=maxInterval
-
withBackoff
Sets theinterval
to pause for between attempts, exponentially backing of to themaxInterval
multiplying successive intervals by theintervalMultiplier
.- Overrides:
withBackoff
in classnet.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
- Throws:
java.lang.NullPointerException
- ifinterval
ormaxInterval
are nulljava.lang.IllegalArgumentException
- ifinterval
is <= 0,interval
is >=maxInterval
or theintervalMultiplier
is <= 1
-
withInterval
Sets theinterval
to pause for between attempts.- Overrides:
withInterval
in classnet.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
- Throws:
java.lang.NullPointerException
- ifinterval
is nulljava.lang.IllegalStateException
- if backoff intervals have already been set viawithBackoff(Duration, Duration)
orwithBackoff(Duration, Duration, int)
-
withMaxAttempts
Sets the max number of attempts to perform. -1 indicates to always attempt.- Overrides:
withMaxAttempts
in classnet.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
-
withMaxDuration
Sets the max duration to perform attempts for.- Overrides:
withMaxDuration
in classnet.jodah.lyra.internal.RecurringPolicy<RetryPolicy>
- Throws:
java.lang.NullPointerException
- ifmaxDuration
is null
-