类 Retry
- java.lang.Object
-
- net.dongliu.commons.retry.Retry
-
public class Retry extends java.lang.ObjectA utils class for do retry. This class can be build fromRetry.Builder, maxRetryTimes and retryBackOff must be set. An example:private static final Retryer retryer = Retryer.newBuilder() .maxRetryTimes(5) .waitBeforeRetry(100) .build(); public void myMethod() { String result = retryer.call(() -> "result"); }
-
-
嵌套类概要
嵌套类 修饰符和类型 类 说明 static classRetry.BuilderBuilder
-
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 <T> Tcall(java.util.function.Supplier<T> supplier)Retry call a block of code, util success or max retry times exceeded.<T> Tcall(java.util.function.Supplier<T> supplier, java.util.function.Predicate<? super T> returnValuePredicate)Retry call a block of code, util success or max retry times exceeded.static Retry.BuildernewBuilder()return a new Buildervoidrun(java.lang.Runnable runnable)retry run a block of code.Retry.BuildertoBuilder()Create a builder with setting of current retry instance.
-
-
-
方法详细资料
-
newBuilder
public static Retry.Builder newBuilder()
return a new Builder
-
toBuilder
public Retry.Builder toBuilder()
Create a builder with setting of current retry instance.
-
run
public void run(java.lang.Runnable runnable)
retry run a block of code.- 参数:
runnable- the code to be run
-
call
public <T> T call(java.util.function.Supplier<T> supplier)
Retry call a block of code, util success or max retry times exceeded.- 参数:
supplier- the code to be run- 返回:
- value returned by supplier
- 抛出:
MaxRetryTimesExceedException- if exceed max retry timesRetryInterruptedException- if is interrupt
-
call
public <T> T call(java.util.function.Supplier<T> supplier, java.util.function.Predicate<? super T> returnValuePredicate)Retry call a block of code, util success or max retry times exceeded.- 参数:
supplier- the code to be runreturnValuePredicate- If retry if return given value. If returnValuePredicate return true, will do retry even if no exception throws.- 返回:
- value returned by supplier
- 抛出:
MaxRetryTimesExceedException- if exceed max retry timesRetryInterruptedException- if is interrupt
-
-