Class RetryBackoffContext.Exponential
- All Implemented Interfaces:
RetryBackoffContext
- Enclosing interface:
- RetryBackoffContext
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.deephaven.util.RetryBackoffContext
RetryBackoffContext.DeadlineExceededException, RetryBackoffContext.Exponential -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionExponential(long initialDelayMillis, long maxDelayMillis, double backoffFactor, double jitterFactor) Create an exponential backoff RetryBackoffContext. -
Method Summary
Modifier and TypeMethodDescriptionlongReturn the time in milliseconds to wait to the next retry.booleanCheck if we have exceeded our time deadline to retry.longReturn the elapsed between the last time toRetryBackoffContext.deadlineExceeded()and the last call toRetryBackoffContext.start(long).voidInform this context object that a retry without applying backoff will be performed.voidreset()Reset this object to a state where no errors have occurred, and it has not been started.intNumber of retries performed since last started.voidstart(long timeOfDeadlineMillis) Start tracking time to execute a backoff retry strategy using this context object.voidstartIfNotAlreadyStarted(long timeOfDeadlineMillis) If not already started, start tracking time to execute a backoff retry strategy using this context object exactly likeRetryBackoffContext.start(long), including defining a deadline.longAbsolute point in time when the last call toRetryBackoffContext.startMillis()was invoked.longReturns the absolute epoch time in milliseconds for the deadline.
-
Field Details
-
INITIAL_DELAY_MILLIS
- See Also:
-
MAX_DELAY_MILLIS
- See Also:
-
BACKOFF_FACTOR
- See Also:
-
JITTER_FACTOR
- See Also:
-
-
Constructor Details
-
Exponential
public Exponential(long initialDelayMillis, long maxDelayMillis, double backoffFactor, double jitterFactor) Create an exponential backoff RetryBackoffContext.- Parameters:
initialDelayMillis- Initial delay to retry. Subsequent retries happen at double the previous retry delay as long as that value does not exceed the max delay; when double the previous value would exceed the max delay and from then on the max delay is used.maxDelayMillis- max delay to apply; once the exponential increase of initial reaches this value, retries happen linearly at this value; they wait the same amount for every subsequent retry.backoffFactor- multiplier factor to apply to a delay to get the next delay; this factor is applied as long as the result is below the max delay, at that point each subsequent delay is that max delay.jitterFactor- a factor to apply to randomize the exact retry delay; a given calculated delay is randomized in the interval[(1-jitterFactor)*delay, (1+jitterFactor)*delay]
-
-
Method Details
-
start
public void start(long timeOfDeadlineMillis) Description copied from interface:RetryBackoffContextStart tracking time to execute a backoff retry strategy using this context object. A deadline is defined when this method is called.- Specified by:
startin interfaceRetryBackoffContext- Parameters:
timeOfDeadlineMillis- absolute time as milliseconds from the epoch to the deadline.
-
startIfNotAlreadyStarted
public void startIfNotAlreadyStarted(long timeOfDeadlineMillis) Description copied from interface:RetryBackoffContextIf not already started, start tracking time to execute a backoff retry strategy using this context object exactly likeRetryBackoffContext.start(long), including defining a deadline. If already started, this call does nothing.- Specified by:
startIfNotAlreadyStartedin interfaceRetryBackoffContext- Parameters:
timeOfDeadlineMillis- absolute time as milliseconds from the epoch to the deadline.
-
reset
public void reset()Description copied from interface:RetryBackoffContextReset this object to a state where no errors have occurred, and it has not been started.- Specified by:
resetin interfaceRetryBackoffContext
-
retryCount
public int retryCount()Description copied from interface:RetryBackoffContextNumber of retries performed since last started. Useful for clients that want to log a retry summary after deadline exceeded.- Specified by:
retryCountin interfaceRetryBackoffContext- Returns:
- number of retries performed.
-
startMillis
public long startMillis()Description copied from interface:RetryBackoffContextAbsolute point in time when the last call toRetryBackoffContext.startMillis()was invoked.- Specified by:
startMillisin interfaceRetryBackoffContext- Returns:
- a milliseconds from the epoch timestamp.
-
deadlineExceeded
public boolean deadlineExceeded()Description copied from interface:RetryBackoffContextCheck if we have exceeded our time deadline to retry.- Specified by:
deadlineExceededin interfaceRetryBackoffContext- Returns:
- true if the retry deadline has been exceeded, false otherwise.
-
noBackoff
public void noBackoff()Description copied from interface:RetryBackoffContextInform this context object that a retry without applying backoff will be performed.If the caller has some criteria to decide to perform retries in some cases without applying a backoff (eg, if a failure due to authentication requires to renew credentials, which makes sense to be done right away since we understand the reason for the failure), the calling this function lets this object keep the right context for the number of retries performed.
If this method is called before a call to
RetryBackoffContext.start(long)has been made, it will be equivalent to having made a call to start tracking time with an infinite deadline before the call.- Specified by:
noBackoffin interfaceRetryBackoffContext
-
backoffMillis
public long backoffMillis()Description copied from interface:RetryBackoffContextReturn the time in milliseconds to wait to the next retry. It is assumed the caller will perform a retry at that future point in time.Thread.sleep(long).If this method is called before a call to
RetryBackoffContext.start(long)has been made, it will be equivalent to having made a call to start tracking time with an infinite deadline before the call, and the initial backoff returned would be zero; subsequent calls would return the initial backoff, and exponentially generated backoffs (as normal) from there.- Specified by:
backoffMillisin interfaceRetryBackoffContext- Returns:
- time in milliseconds to wait until the next retry.
-
elapsedMillis
public long elapsedMillis()Description copied from interface:RetryBackoffContextReturn the elapsed between the last time toRetryBackoffContext.deadlineExceeded()and the last call toRetryBackoffContext.start(long).- Specified by:
elapsedMillisin interfaceRetryBackoffContext- Returns:
- elapsed time in milliseconds.
-
timeOfDeadlineMillis
public long timeOfDeadlineMillis()Description copied from interface:RetryBackoffContextReturns the absolute epoch time in milliseconds for the deadline. Note this method only returns a valid deadline if start has already been called on this Context.- Specified by:
timeOfDeadlineMillisin interfaceRetryBackoffContext- Returns:
- epoch time of deadline in milliseconds.
-