Class ExponentialBackoffDelayPolicy

java.lang.Object
com.cloudera.cdp.http.ExponentialBackoffDelayPolicy
All Implemented Interfaces:
DelayPolicy

public class ExponentialBackoffDelayPolicy extends Object implements DelayPolicy
Implement an exponential backoff policy. For a given 'base' and 'growthFactor' a delay will be computed to be:

'base' * 'growthFactor' ^ (attempts - 1)

For example:

  • base = 500ms, growthFactor = 2
  • attempts = 1, delay = 500 * 2^0 = 500ms
  • attempts = 2, delay = 500 * 2^1 = 1sec
  • attempts = 3, delay = 500 * 2^2 = 2sec
Optional jitter causes each computed delay to vary from its deterministic value, as computed above, up to a certain percentage. For example:

  • base = 500ms, growthFactor = 2, jitterPercentage = 5
  • attempts = 1, delay = 500 * 2^0 +/- 25ms = 475ms - 525ms
  • attempts = 2, delay = 500 * 2^1 +/- 50ms = 900ms - 1100ms
  • attempts = 3, delay = 500 * 2^2 +/- 100ms= 1.9sec - 2.1sec
  • Constructor Details

    • ExponentialBackoffDelayPolicy

      public ExponentialBackoffDelayPolicy(int growthFactor, Duration base)
      Constructs an exponential backoff delay policy with the given 'growthFactor' and 'base'. There is no jitter applied.
      Parameters:
      growthFactor - The growth factor between delays. Must be positive
      base - The base. Must be a positive duration.
    • ExponentialBackoffDelayPolicy

      public ExponentialBackoffDelayPolicy(int growthFactor, Duration base, int jitterPercentage)
      Constructs an exponential backoff delay policy with the given 'growthFactor', 'base', and 'jitterPercentage'.
      Parameters:
      growthFactor - The growth factor between delays. Must be positive
      base - The base. Must be a positive duration.
      jitterPercentage - Percentage of jitter range applied to delay. Must non-negative.
  • Method Details

    • delay

      public Duration delay(int attempts)
      Description copied from interface: DelayPolicy
      Returns the delay needed before attempting the next retry.
      Specified by:
      delay in interface DelayPolicy
      Parameters:
      attempts - The number of attempts made to make the call
      Returns:
      The duration to wait