package h2o.utils.reliable;

import java.util.concurrent.TimeUnit;

/**
 * Created by zhangjianwei on 2016/12/27.
 */
public class ReliableExecution {

    private final int tryTimes; // 尝试次数

    private final long tryInterval; // 尝试时间间隔

    public ReliableExecution() {
        this.tryTimes = 3;
        this.tryInterval = 5000;
    }

    public ReliableExecution(int tryTimes, long tryInterval) {
        this.tryTimes = tryTimes;
        this.tryInterval = tryInterval;
    }

    public void exec(ReliableExecutor executor) {

        for (int i = 1; i <= tryTimes; i++) {

            try {

                if (executor.exec(i)) {
                    break;
                }

            } catch (Exception e) {

                if (executor.exceptionHandler(i, e)) {

                    try {
                        TimeUnit.MILLISECONDS.sleep(tryInterval);
                    } catch (Exception e1) {
                    }

                } else {
                    break;
                }

            }
        }

    }

}

@@ -606,32 +606,33 @@
             if (
+ 
 executor.exec(i)
@@ -631,16 +631,17 @@
 .exec(i)
+ 
 ) %7B%0A    
@@ -739,16 +739,19 @@
     if (
+ ! 
 executor
@@ -773,21 +773,21 @@
 er(i, e)
+ 
 ) %7B%0A
-%0A
         
@@ -779,32 +779,69 @@
 e) ) %7B%0A         
+           break;%0A                %7D%0A%0A
            try %7B
@@ -839,22 +839,22 @@
     
-try %7B%0A
+ %7D%0A%0A  
         
     
@@ -841,32 +841,40 @@
    %7D%0A%0A          
+  try %7B%0A
                 
@@ -923,32 +923,24 @@
             
-    
-    
 %7D catch (Exc
@@ -968,103 +968,10 @@
     
-        %7D%0A%0A                %7D else %7B%0A                    break;%0A                %7D%0A%0A            
 %7D
+%0A
 %0A   

fix bug 失败重试时没有延时