Package org.apache.beam.sdk.util
Class FluentBackoff
- java.lang.Object
-
- org.apache.beam.sdk.util.FluentBackoff
-
public final class FluentBackoff extends java.lang.Object
A fluent builder forBackOff
objects that allows customization of the retry algorithm.
-
-
Field Summary
Fields Modifier and Type Field Description static FluentBackoff
DEFAULT
By default theBackOff
created by this builder will use exponential backoff (base exponent 1.5) with an initial backoff of 1 second.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BackOff
backoff()
Instantiates aBackOff
that will obey the current configuration.java.lang.String
toString()
FluentBackoff
withExponent(double exponent)
Returns a copy of thisFluentBackoff
that instead uses the specified exponent to control the exponential growth of delay.FluentBackoff
withInitialBackoff(org.joda.time.Duration initialBackoff)
Returns a copy of thisFluentBackoff
that instead uses the specified initial backoff duration.FluentBackoff
withMaxBackoff(org.joda.time.Duration maxBackoff)
Returns a copy of thisFluentBackoff
that limits the maximum backoff of an individual attempt to the specified duration.FluentBackoff
withMaxCumulativeBackoff(org.joda.time.Duration maxCumulativeBackoff)
Returns a copy of thisFluentBackoff
that limits the total time spent in backoff returned across all calls toBackOff.nextBackOffMillis()
.FluentBackoff
withMaxRetries(int maxRetries)
Returns a copy of thisFluentBackoff
that limits the total number of retries, aka the total number of calls toBackOff.nextBackOffMillis()
before returningBackOff.STOP
.
-
-
-
Field Detail
-
DEFAULT
public static final FluentBackoff DEFAULT
By default theBackOff
created by this builder will use exponential backoff (base exponent 1.5) with an initial backoff of 1 second. These parameters can be overridden withwithExponent(double)
andwithInitialBackoff(Duration)
, respectively, and the maximum backoff after exponential increase can be capped usingwithMaxBackoff(Duration)
.The default
BackOff
does not limit the number of retries. To limit the backoff, the maximum total number of retries can be set usingwithMaxRetries(int)
. The total time spent in backoff can be time-bounded as well by configuringwithMaxCumulativeBackoff(Duration)
. If either of these limits are reached, calls toBackOff.nextBackOffMillis()
will returnBackOff.STOP
to signal that no more retries should continue.
-
-
Method Detail
-
backoff
public BackOff backoff()
Instantiates aBackOff
that will obey the current configuration.- See Also:
FluentBackoff
-
withExponent
public FluentBackoff withExponent(double exponent)
Returns a copy of thisFluentBackoff
that instead uses the specified exponent to control the exponential growth of delay.Does not modify this object.
- See Also:
FluentBackoff
-
withInitialBackoff
public FluentBackoff withInitialBackoff(org.joda.time.Duration initialBackoff)
Returns a copy of thisFluentBackoff
that instead uses the specified initial backoff duration.Does not modify this object.
- See Also:
FluentBackoff
-
withMaxBackoff
public FluentBackoff withMaxBackoff(org.joda.time.Duration maxBackoff)
Returns a copy of thisFluentBackoff
that limits the maximum backoff of an individual attempt to the specified duration.Does not modify this object.
- See Also:
FluentBackoff
-
withMaxCumulativeBackoff
public FluentBackoff withMaxCumulativeBackoff(org.joda.time.Duration maxCumulativeBackoff)
Returns a copy of thisFluentBackoff
that limits the total time spent in backoff returned across all calls toBackOff.nextBackOffMillis()
.Does not modify this object.
- See Also:
FluentBackoff
-
withMaxRetries
public FluentBackoff withMaxRetries(int maxRetries)
Returns a copy of thisFluentBackoff
that limits the total number of retries, aka the total number of calls toBackOff.nextBackOffMillis()
before returningBackOff.STOP
.Does not modify this object.
- See Also:
FluentBackoff
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-