com.google.bitcoin.utils
Class ExponentialBackoff

java.lang.Object
  extended by com.google.bitcoin.utils.ExponentialBackoff
All Implemented Interfaces:
Comparable<ExponentialBackoff>

public class ExponentialBackoff
extends Object
implements Comparable<ExponentialBackoff>

Tracks successes and failures and calculates a time to retry the operation.

The retries are exponentially backed off, up to a maximum interval. On success the back off interval is reset.


Nested Class Summary
static class ExponentialBackoff.Params
          Parameters to configure a particular kind of exponential backoff.
 
Field Summary
static int DEFAULT_INITIAL_MILLIS
           
static int DEFAULT_MAXIMUM_MILLIS
           
static float DEFAULT_MULTIPLIER
           
 
Constructor Summary
ExponentialBackoff(ExponentialBackoff.Params params)
           
 
Method Summary
 int compareTo(ExponentialBackoff other)
           
 long getRetryTime()
          Get the next time to retry, in milliseconds since the epoch
 String toString()
           
 void trackFailure()
          Track a failure - multiply the back off interval by the multiplier
 void trackSuccess()
          Track a success - reset back off interval to the initial value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_INITIAL_MILLIS

public static final int DEFAULT_INITIAL_MILLIS
See Also:
Constant Field Values

DEFAULT_MULTIPLIER

public static final float DEFAULT_MULTIPLIER
See Also:
Constant Field Values

DEFAULT_MAXIMUM_MILLIS

public static final int DEFAULT_MAXIMUM_MILLIS
See Also:
Constant Field Values
Constructor Detail

ExponentialBackoff

public ExponentialBackoff(ExponentialBackoff.Params params)
Method Detail

trackSuccess

public void trackSuccess()
Track a success - reset back off interval to the initial value


trackFailure

public void trackFailure()
Track a failure - multiply the back off interval by the multiplier


getRetryTime

public long getRetryTime()
Get the next time to retry, in milliseconds since the epoch


compareTo

public int compareTo(ExponentialBackoff other)
Specified by:
compareTo in interface Comparable<ExponentialBackoff>

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2014. All rights reserved.