Class ExponentialBackoffContext

java.lang.Object
io.deephaven.util.ExponentialBackoffContext

public class ExponentialBackoffContext
extends Object
Helper class to keep the context required to execute an exponential backoff strategy for retries. Borrowing the retry backoff algorithm from gRPC reconnection
  • Field Details

  • Constructor Details

  • Method Details

    • start

      public void start​(long retryInitialDelayMillis, long retryMaxDelayMillis, long retryMaxDurationMillis)
      Start tracking time to execute an exponential backoff retry strategy using this context object. A deadline is defined when this method is called.
      Parameters:
      retryInitialDelayMillis - 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.
      retryMaxDelayMillis - 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.
      retryMaxDurationMillis - upper bound on the total time to retry; after this time is exceeded we stop retrying.
    • retryCount

      public int retryCount()
      Number of retries performed. Useful for clients that want to log a retry summary after deadline exceeded.
      Returns:
      number of retries performed.
    • startMillis

      public long startMillis()
      Absolute point in time when the last call to startMillis() was invoked.
      Returns:
      a milliseconds from the epoch timestamp.
    • deadlineExceeded

      public boolean deadlineExceeded()
      Check if we have exceeded our time deadline to retry.
      Returns:
      true if the retry deadline has been exceeded, false otherwise.
    • noBackoff

      public void noBackoff()
      Inform 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.
    • backoffMillis

      public long backoffMillis()
      Return the time in milliseconds to wait to the next retry. It is assumed the caller will perform a retry after performing this way in some way, eg, calling Thread.sleep(long).
      Returns:
      time in milliseconds to wait until the next retry.
    • elapsedMillis

      public long elapsedMillis()
      Return the elapsed between the last time to deadlineExceeded() and the last call to start(long, long, long).
      Returns:
      elapsed time in milliseconds.