Package org.bitcoinj.utils
Class ExponentialBackoff
- java.lang.Object
-
- org.bitcoinj.utils.ExponentialBackoff
-
- All Implemented Interfaces:
java.lang.Comparable<ExponentialBackoff>
public class ExponentialBackoff extends java.lang.Object implements java.lang.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
Nested Classes Modifier and Type Class Description static classExponentialBackoff.ParamsParameters to configure a particular kind of exponential backoff.
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_INITIAL_MILLISstatic intDEFAULT_MAXIMUM_MILLISstatic floatDEFAULT_MULTIPLIER
-
Constructor Summary
Constructors Constructor Description ExponentialBackoff(ExponentialBackoff.Params params)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(ExponentialBackoff other)longgetRetryTime()Get the next time to retry, in milliseconds since the epochjava.lang.StringtoString()voidtrackFailure()Track a failure - multiply the back off interval by the multipliervoidtrackSuccess()Track a success - reset back off interval to the initial value
-
-
-
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 final 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:
compareToin interfacejava.lang.Comparable<ExponentialBackoff>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-