Source:
<code>public void downloadFiles( List<? extends S3Artifact> s3Artifacts, SingularityExecutorTask task ) throws InterruptedException { <START> final List<CompletableFutureHolder> futures = Lists.newArrayListWithCapacity( <END> s3Artifacts.size() ); for (S3Artifact s3Artifact : s3Artifacts) { String destination = task .getArtifactPath(s3Artifact, task.getTaskDefinition().getTaskDirectoryPath()) .toString(); ArtifactDownloadRequest artifactDownloadRequest = new ArtifactDownloadRequest( destination, s3Artifact, Optional.of(executorConfiguration.getLocalDownloadServiceTimeoutMillis()) ); task .getLog() .debug( "Requesting from {}", artifactDownloadRequest, s3Configuration.getLocalDownloadSocket().get() ); try { CompletableFuture<ContentResponse> future = new CompletableFuture<>(); httpClient .newRequest(localDownloadPath) .method(HttpMethod.POST) .content( new BytesContentProvider( objectMapper.writeValueAsBytes(artifactDownloadRequest) ), "application/json" ) .send(new CompletableFutureResponseListener(future)); futures.add( new CompletableFutureHolder(future, System.currentTimeMillis(), s3Artifact) ); } catch (JsonProcessingException e) { throw new RuntimeException(e); } } for (CompletableFutureHolder future : futures) { ContentResponse response = future.getReponse(); task .getLog() .debug( "Future for got status code after {}", future.s3Artifact.getName(), response.getStatus(), JavaUtils.duration(future.start) ); if (response.getStatus() != 200) { throw new IllegalStateException("Got status code:" + response.getStatus()); } } }</code><technical_language>possibly refactor local download fetchers a single implementation takes in S3Artifact -> CompletableFuture function, if consolidating implementations is worth it</technical_language>

Target:
public void downloadFiles( List<? extends S3Artifact> s3Artifacts, SingularityExecutorTask task ) throws InterruptedException { final List<CompletableFutureHolder> futures = Lists.newArrayListWithCapacity( s3Artifacts.size() ); for (S3Artifact s3Artifact : s3Artifacts) { String destination = task .getArtifactPath(s3Artifact, task.getTaskDefinition().getTaskDirectoryPath()) .toString(); ArtifactDownloadRequest artifactDownloadRequest = new ArtifactDownloadRequest( destination, s3Artifact, Optional.of(executorConfiguration.getLocalDownloadServiceTimeoutMillis()) ); task .getLog() .debug( "Requesting from {}", artifactDownloadRequest, s3Configuration.getLocalDownloadSocket().get() ); try { CompletableFuture<ContentResponse> future = new CompletableFuture<>(); httpClient .newRequest(localDownloadPath) .method(HttpMethod.POST) .content( new BytesContentProvider( objectMapper.writeValueAsBytes(artifactDownloadRequest) ), "application/json" ) .send(new CompletableFutureResponseListener(future)); futures.add( new CompletableFutureHolder(future, System.currentTimeMillis(), s3Artifact) ); } catch (JsonProcessingException e) { throw new RuntimeException(e); } } for (CompletableFutureHolder future : futures) { ContentResponse response = future.getResponse(); task .getLog() .debug( "Future for got status code after {}", future.s3Artifact.getName(), response.getStatus(), JavaUtils.duration(future.start) ); if (response.getStatus() != 200) { throw new IllegalStateException("Got status code:" + response.getStatus()); } } }