public < T > T execute ( final Callable < T > callable ) throws Exception { int attempts = 0 ; int maxAttempts = retryPolicy . getMaxAttempts ( ) ; long delay = retryPolicy . getDelay ( ) ; TimeUnit timeUnit = retryPolicy . getTimeUnit ( ) ; while ( attempts < maxAttempts ) { try { attempts ++ ; beforeCall ( ) ; T result = callable . call ( ) ; afterCall ( result ) ; return result ; } catch ( Exception e ) { onException ( e ) ; if ( attempts >= maxAttempts ) { onMaxAttempts ( e ) ; throw e ; } beforeWait ( ) ; sleep ( timeUnit . toMillis ( delay ) ) ; afterWait ( ) ; } } return null ; }
Execute the callable with retries .