Source:
<code>private HttpURLConnection connect(final URI uri, final String method, final byte[] entity, final Map<String, List<String>> headers) throws URISyntaxException, IOException, TimeoutException, InterruptedException, HeliosException { final Endpoint endpoint = endpointIterator.next(); final URI endpointUri = endpoint.getUri(); final String fullpath = endpointUri.getPath() + uri.getPath(); final String uriScheme = endpointUri.getScheme(); final URI ipUri = new URI( uriScheme, endpointUri.getUserInfo(), endpoint.getIp().getHostAddress(), endpointUri.getPort(), fullpath, uri.getQuery(), null); AgentProxy agentProxy = null; <START> Deque<Identity> identities = Queues.newArrayDeque(); <END> try { if (uriScheme.equals("https")) { agentProxy = AgentProxies.newInstance(); for (final Identity identity : agentProxy.list()) { if (identity.getPublicKey().getAlgorithm().equals("RSA")) { identities.offerLast(identity); } } } } catch (Exception e) { log.warn("Couldn't get identities from ssh-agent", e); } try { do { final Identity identity = identities.poll(); try { log.debug("connecting to {}", ipUri); final HttpURLConnection connection = connect0( ipUri, method, entity, headers, endpointUri.getHost(), agentProxy, identity); final int responseCode = connection.getResponseCode(); if (((responseCode == HTTP_FORBIDDEN) || (responseCode == HTTP_UNAUTHORIZED)) && !identities.isEmpty()) { log.debug("retrying with next SSH identity since failed", identity.getComment()); continue; } return connection; } catch (ConnectException | SocketTimeoutException | UnknownHostException e) { log.debug(e.toString()); throw e; } } while (false); } finally { if (agentProxy != null) { agentProxy.close(); } } throw new HeliosException("foo"); }</code><technical_language>I this a regular Queue / LinkedList, insert end remove head</technical_language>

Target:
private HttpURLConnection connect(final URI uri, final String method, final byte[] entity, final Map<String, List<String>> headers) throws URISyntaxException, IOException, TimeoutException, InterruptedException, HeliosException { final Endpoint endpoint = endpointIterator.next(); final URI endpointUri = endpoint.getUri(); final String fullpath = endpointUri.getPath() + uri.getPath(); final String uriScheme = endpointUri.getScheme(); final URI ipUri = new URI( uriScheme, endpointUri.getUserInfo(), endpoint.getIp().getHostAddress(), endpointUri.getPort(), fullpath, uri.getQuery(), null); AgentProxy agentProxy = null; Deque<Identity> identities = Queues.newArrayDeque(); try { if (uriScheme.equals("https")) { agentProxy = AgentProxies.newInstance(); for (final Identity identity : agentProxy.list()) { if (identity.getPublicKey().getAlgorithm().equals("RSA")) { identities.offerLast(identity); } } } } catch (Exception e) { log.warn("Couldn't get identities from ssh-agent", e); } try { do { final Identity identity = identities.poll(); try { log.debug("connecting to {}", ipUri); final HttpURLConnection connection = connect0( ipUri, method, entity, headers, endpointUri.getHost(), agentProxy, identity); final int responseCode = connection.getResponseCode(); if (((responseCode == HTTP_FORBIDDEN) || (responseCode == HTTP_UNAUTHORIZED)) && !identities.isEmpty()) { log.debug("retrying with next SSH identity since failed", identity.getComment()); continue; } return connection; } catch (ConnectException | SocketTimeoutException | UnknownHostException e) { log.debug(e.toString()); throw e; } } while (false); } finally { if (agentProxy != null) { agentProxy.close(); } } throw new HeliosException("Unable to connect to master"); }