1 18 package org.apache.tools.ant.util; 19 20 import java.io.IOException ; 21 22 import org.apache.tools.ant.Project; 23 import org.apache.tools.ant.Task; 24 25 30 public class RetryHandler { 31 32 private int retriesAllowed = 0; 33 private Task task; 34 35 41 public RetryHandler(int retriesAllowed, Task task) { 42 this.retriesAllowed = retriesAllowed; 43 this.task = task; 44 } 45 46 53 public void execute(Retryable exe, String desc) throws IOException { 54 int retries = 0; 55 while (true) { 56 try { 57 exe.execute(); 58 break; 59 } catch (IOException e) { 60 retries++; 61 if (retries > this.retriesAllowed && this.retriesAllowed > -1) { 62 task.log("try #" + retries + ": IO error (" 63 + desc + "), number of maximum retries reached (" 64 + this.retriesAllowed + "), giving up", Project.MSG_WARN); 65 throw e; 66 } else { 67 task.log("try #" + retries + ": IO error (" + desc 68 + "), retrying", Project.MSG_WARN); 69 } 70 } 71 } 72 } 73 74 } 75 | Popular Tags |