package com.nirima.jenkins.plugins.docker.utils;

import com.nirima.docker.client.DockerException;
import hudson.model.TaskListener;
import hudson.slaves.ComputerLauncher;
import hudson.slaves.DelegatingComputerLauncher;
import hudson.slaves.SlaveComputer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;


public class RetryingComputerLauncher extends DelegatingComputerLauncher {

    private static final Logger log = LoggerFactory.getLogger(RetryingComputerLauncher.class);

    /**
     * How many times to retry the launch?
     */
    private final int retries = 3;

    /**
     * time (ms) to back off between retries?
     */
    private final int pause   = 5000;

    public RetryingComputerLauncher(ComputerLauncher delegate) {
        super(delegate);
    }

    @Override
    public void launch(SlaveComputer computer, TaskListener listener) throws IOException, InterruptedException {

        for( int i=0;i<retries;i++) {
            try {
                super.launch(computer, listener);
                return;
            } catch(Exception ex) {
                log.info("Launch failed on attempt {}", i);
            }
            Thread.sleep(pause);
        }
        throw new IOException("SSH Launch failed");
    }
}

@@ -529,42 +529,45 @@
   * 
-How many times to retry the launch
+time (ms) to back off between retries
 ?%0A  
@@ -598,19 +598,22 @@
 int 
-retries = 3
+pause   = 5000
 ;%0A%0A 
@@ -630,91 +630,90 @@
   * 
-time (ms) to back off between retries?%0A     */%0A    private final int pause   = 5000
+Let us know when to pause the launch.%0A     */%0A    private boolean hasTried = false
 ;%0A%0A 
@@ -935,25 +935,24 @@
 ption %7B%0A
-%0A
         
 for( int
@@ -947,170 +947,24 @@
     
-for( int i=0;i%3Cretries;i++) %7B%0A            try %7B%0A                super.launch(computer, listener);%0A                return;%0A            %7D catch(Exception ex) %7B%0A    
+if (hasTried) %7B%0A
     
@@ -998,42 +998,34 @@
 iled
- on attempt %7B%7D%22, i);%0A            %7D
+, pausing before retry.%22);
 %0A   
@@ -1076,50 +1076,65 @@
     
-throw new IOException(%22SSH Launch failed%22)
+super.launch(computer, listener);%0A        hasTried = true
 ;%0A  

Check if we have tried, pause if we have