FileDocCategorySizeDatePackage
RetryHandler.javaAPI DocApache Ant 1.702685Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.util

RetryHandler

public class RetryHandler extends Object
A simple utility class to take a piece of code (that implements Retryable interface) and executes that with possibility to retry the execution in case of IOException.

Fields Summary
private int
retriesAllowed
private org.apache.tools.ant.Task
task
Constructors Summary
public RetryHandler(int retriesAllowed, org.apache.tools.ant.Task task)
Create a new RetryingHandler.

param
retriesAllowed how many times to retry
param
task the Ant task that is is executed from, used for logging only


                                  
         
        this.retriesAllowed = retriesAllowed;
        this.task = task;
    
Methods Summary
public voidexecute(Retryable exe, java.lang.String desc)
Execute the Retryable code with specified number of retries.

param
exe the code to execute
param
desc some descriptive text for this piece of code, used for logging
throws
IOException if the number of retries has exceeded the allowed limit

        int retries = 0;
        while (true) {
            try {
                exe.execute();
                break;
            } catch (IOException e) {
                retries++;
                if (retries > this.retriesAllowed && this.retriesAllowed > -1) {
                    task.log("try #" + retries + ": IO error ("
                            + desc + "), number of maximum retries reached ("
                            + this.retriesAllowed + "), giving up", Project.MSG_WARN);
                    throw e;
                } else {
                    task.log("try #" + retries + ": IO error (" + desc
                             + "), retrying", Project.MSG_WARN);
                }
            }
        }