|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.twitter.common.util.BackoffHelper
public class BackoffHelper
A utility for dealing with backoffs of retryable actions.
TODO(John Sirois): investigate synergies with BackoffDecider.
| Nested Class Summary | |
|---|---|
static class |
BackoffHelper.BackoffStoppedException
Occurs after the backoff strategy should stop. |
| Constructor Summary | |
|---|---|
BackoffHelper()
Creates a new BackoffHelper that uses truncated binary backoff starting at a 1 second backoff and maxing out at a 1 minute backoff. |
|
BackoffHelper(Amount<Long,Time> initialBackoff,
Amount<Long,Time> maxBackoff)
Creates a new BackoffHelper that uses truncated binary backoff starting at the given initialBackoff and maxing out at the given maxBackoff. |
|
BackoffHelper(Amount<Long,Time> initialBackoff,
Amount<Long,Time> maxBackoff,
boolean stopAtMax)
Creates a new BackoffHelper that uses truncated binary backoff starting at the given initialBackoff and maxing out at the given maxBackoff. |
|
BackoffHelper(BackoffStrategy backoffStrategy)
Creates a BackoffHelper that uses the given backoffStrategy to calculate backoffs
between retries. |
|
| Method Summary | ||
|---|---|---|
|
doUntilResult(ExceptionalSupplier<T,E> task)
Executes the given task using the configured backoff strategy until the task succeeds as indicated by returning a non-null value. |
|
|
doUntilSuccess(ExceptionalSupplier<Boolean,E> task)
Executes the given task using the configured backoff strategy until the task succeeds as indicated by returning true. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public BackoffHelper()
public BackoffHelper(Amount<Long,Time> initialBackoff,
Amount<Long,Time> maxBackoff)
initialBackoff and maxing out at the given maxBackoff.
initialBackoff - the initial amount of time to back offmaxBackoff - the maximum amount of time to back off
public BackoffHelper(Amount<Long,Time> initialBackoff,
Amount<Long,Time> maxBackoff,
boolean stopAtMax)
initialBackoff and maxing out at the given maxBackoff. This will either:
stopAtMax == true : throw BackoffExpiredException when maxBackoff is
reachedstopAtMax == false : continue backing off with maxBackoff
initialBackoff - the initial amount of time to back offmaxBackoff - the maximum amount of time to back offstopAtMax - if true, this will throw BackoffStoppedException when the max backoff is
reachedpublic BackoffHelper(BackoffStrategy backoffStrategy)
backoffStrategy to calculate backoffs
between retries.
backoffStrategy - the backoff strategy to use| Method Detail |
|---|
public <E extends Exception> void doUntilSuccess(ExceptionalSupplier<Boolean,E> task)
throws InterruptedException,
BackoffHelper.BackoffStoppedException,
E extends Exception
true.
task - the retryable task to execute until success
InterruptedException - if interrupted while waiting for the task to execute successfully
BackoffHelper.BackoffStoppedException - if the backoff stopped unsuccessfully
E - if the task throws
E extends Exception
public <T,E extends Exception> T doUntilResult(ExceptionalSupplier<T,E> task)
throws InterruptedException,
BackoffHelper.BackoffStoppedException,
E extends Exception
task - the retryable task to execute until success
InterruptedException - if interrupted while waiting for the task to execute successfully
BackoffHelper.BackoffStoppedException - if the backoff stopped unsuccessfully
E - if the task throws
E extends Exception
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||