public long calcBackoff ( int previousAttempts , long totalElapsedTimeMillis , Error error ) { long backoffMillis = ( long ) ( Math . pow ( 2 , previousAttempts ) * 1000 ) + new Random ( ) . nextInt ( 1000 ) ; if ( totalElapsedTimeMillis + backoffMillis > maxRetryTimeMillis ) { logger . info ( "Elapsed time " + totalElapsedTimeMillis + " + backoff time " + backoffMillis + " exceeds max retry time " + maxRetryTimeMillis + ", exiting retry loop" ) ; return - 1 ; } return backoffMillis ; }
The backoff calculation routine . Uses exponential backoff . If the maximum elapsed time has expired this calculation returns - 1 causing the caller to fall out of the retry loop .