类 Retry


  • public class Retry
    extends java.lang.Object
    A 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 class  Retry.Builder
      Builder
    • 方法概要

      所有方法 静态方法 实例方法 具体方法 
      修饰符和类型 方法 说明
      <T> T call​(java.util.function.Supplier<T> supplier)
      Retry call a block of code, util success or max retry times exceeded.
      <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.
      static Retry.Builder newBuilder()
      return a new Builder
      void run​(java.lang.Runnable runnable)
      retry run a block of code.
      Retry.Builder toBuilder()
      Create a builder with setting of current retry instance.
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 方法详细资料

      • 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 times
        RetryInterruptedException - 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 run
        returnValuePredicate - 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 times
        RetryInterruptedException - if is interrupt