Source:
<code>public HttpConnectionInterceptorContext interceptResponse(HttpConnectionInterceptorContext context) { try { HttpURLConnection urlConnection = context.connection.getConnection(); int code = urlConnection.getResponseCode(); if (code != 429) { return context; } <START> AtomicInteger attemptCounter = context.getState(this, "attempt", AtomicInteger.class); <END> if (attemptCounter == null) { context.setState(this, "attempt", (attemptCounter = new AtomicInteger())); } int attempt = attemptCounter.getAndIncrement(); if (attempt < numberOfReplays && context.connection.getNumberOfRetriesRemaining() > 0) { long sleepTime = 0l; String retryAfter = (preferRetryAfter) ? urlConnection.getHeaderField ("Retry-After") : null; if (retryAfter != null) { sleepTime = Long.parseLong(retryAfter) * 1000; } else { sleepTime = initialSleep * Math.round(Math.pow(2, attempt)); } InputStream errorStream = urlConnection.getErrorStream(); try { String errorString = IOUtils.toString(errorStream, "UTF-8"); logger.warning(errorString + " will retry in " + sleepTime + " ms"); } finally { errorStream.close(); } logger.fine("Too many requests backing off for " + sleepTime + " ms."); try { TimeUnit.MILLISECONDS.sleep(sleepTime); } catch (InterruptedException e) { logger.fine("Interrupted during 429 backoff wait."); } context.replayRequest = true; return context; } else { return context; } } catch (IOException e) { throw new HttpConnectionInterceptorException(e); } }</code><technical_language>Keys "attempt" defined constants</technical_language>

Target:
public HttpConnectionInterceptorContext interceptResponse(HttpConnectionInterceptorContext context) { try { HttpURLConnection urlConnection = context.connection.getConnection(); int code = urlConnection.getResponseCode(); if (code != 429) { return context; } AtomicInteger attemptCounter = context.getState(this, ATTEMPT, AtomicInteger.class); if (attemptCounter == null) { context.setState(this, ATTEMPT, (attemptCounter = new AtomicInteger())); } int attempt = attemptCounter.getAndIncrement(); if (attempt < numberOfReplays && context.connection.getNumberOfRetriesRemaining() > 0) { long sleepTime = initialSleep * Math.round(Math.pow(2, attempt)); String retryAfter = preferRetryAfter ? urlConnection.getHeaderField ("Retry-After") : null; if (retryAfter != null) { try { sleepTime = Long.parseLong(retryAfter) * 1000; if (sleepTime > RETRY_AFTER_CAP) { sleepTime = RETRY_AFTER_CAP; logger.severe("Server specified Retry-After value in excess of one " + "hour, capping retry."); } } catch (NumberFormatException nfe) { logger.warning("Invalid Retry-After value from server falling back to " + "default backoff."); } } InputStream errorStream = urlConnection.getErrorStream(); try { String errorString = IOUtils.toString(errorStream, "UTF-8"); logger.warning(errorString + " will retry in " + sleepTime + " ms"); } finally { errorStream.close(); } logger.fine("Too many requests backing off for " + sleepTime + " ms."); try { TimeUnit.MILLISECONDS.sleep(sleepTime); } catch (InterruptedException e) { logger.fine("Interrupted during 429 backoff wait."); } context.replayRequest = true; return context; } else { return context; } } catch (IOException e) { throw new HttpConnectionInterceptorException(e); } }