Package net.jodah.lyra.config
Class RecoveryPolicy
java.lang.Object
net.jodah.lyra.internal.RecurringPolicy<RecoveryPolicy>
net.jodah.lyra.config.RecoveryPolicy
public class RecoveryPolicy extends net.jodah.lyra.internal.RecurringPolicy<RecoveryPolicy>
Policy that defines how recovery should be performed.
-
Constructor Summary
Constructors Constructor Description RecoveryPolicy()
Creates a recovery policy that always recovers. -
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.RecoveryPolicy
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.RecoveryPolicy
withBackoff(Duration interval, Duration maxInterval, int intervalMultiplier)
Sets theinterval
to pause for between attempts, exponentially backing of to themaxInterval
multiplying successive intervals by theintervalMultiplier
.RecoveryPolicy
withInterval(Duration interval)
Sets theinterval
to pause for between attempts.RecoveryPolicy
withMaxAttempts(int maxAttempts)
Sets the max number of attempts to perform.RecoveryPolicy
withMaxDuration(Duration maxDuration)
Sets the max duration to perform attempts for.
-
Constructor Details
-
RecoveryPolicy
public RecoveryPolicy()Creates a recovery policy that always recovers.
-
-
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<RecoveryPolicy>
-
getInterval
Returns the interval between attempts.- Overrides:
getInterval
in classnet.jodah.lyra.internal.RecurringPolicy<RecoveryPolicy>
- 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<RecoveryPolicy>
- See Also:
withBackoff(Duration, Duration, int)
-
getMaxAttempts
public int getMaxAttempts()Returns the max attempts.- Overrides:
getMaxAttempts
in classnet.jodah.lyra.internal.RecurringPolicy<RecoveryPolicy>
- See Also:
withMaxAttempts(int)
-
getMaxDuration
Returns the max duration to perform attempts for.- Overrides:
getMaxDuration
in classnet.jodah.lyra.internal.RecurringPolicy<RecoveryPolicy>
- See Also:
withMaxDuration(Duration)
-
getMaxInterval
Returns the max interval between backoff attempts.- Overrides:
getMaxInterval
in classnet.jodah.lyra.internal.RecurringPolicy<RecoveryPolicy>
- 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<RecoveryPolicy>
- 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<RecoveryPolicy>
- 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<RecoveryPolicy>
- 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<RecoveryPolicy>
-
withMaxDuration
Sets the max duration to perform attempts for.- Overrides:
withMaxDuration
in classnet.jodah.lyra.internal.RecurringPolicy<RecoveryPolicy>
- Throws:
java.lang.NullPointerException
- ifmaxDuration
is null
-