Source:
private static <SERVICE, RESPONSE extends PaxosResponse> PaxosResponses<RESPONSE> collectResponses( ImmutableList<SERVICE> remotes, final Function<SERVICE, RESPONSE> request, int quorumSize, Map<SERVICE, ExecutorService> executors, Duration remoteRequestTimeout, boolean shortcircuitIfQuorumImpossible) { MultiplexingCompletionService<SERVICE, RESPONSE> responseCompletionService = MultiplexingCompletionService.create(executors); List<Future<RESPONSE>> allFutures = Lists.newArrayList(); for (final SERVICE remote : remotes) { try { allFutures.add(responseCompletionService.submit(remote, () -> request.apply(remote))); } catch (RejectedExecutionException e) { requestExecutionRejection.mark(); if (shouldLogDiagnosticInformation()) { log.info("Quorum checker executor rejected task", e); log.info("Rate of execution rejections: {}", SafeArg.of("rate1m", requestExecutionRejection.getOneMinuteRate())); } } } List<Throwable> encounteredErrors = Lists.newArrayList(); boolean interrupted = false; PaxosResponses<RESPONSE> receivedResponses = new PaxosResponses<>(remotes.size(), quorumSize, shortcircuitIfQuorumImpossible); try { long deadline = System.nanoTime() + remoteRequestTimeout.toNanos(); while (receivedResponses.shouldProcessNextRequest()) { try { Future<RESPONSE> responseFuture = responseCompletionService.poll( deadline - System.nanoTime(), TimeUnit.NANOSECONDS); if (timedOut(responseFuture)) { break; } receivedResponses.add(responseFuture.get()); } catch (ExecutionException e) { receivedResponses.markFailure(); encounteredErrors.add(e.getCause()); } } } catch (InterruptedException e) { log.warn("paxos request interrupted", e); interrupted = true; } finally { cancelOutstandingRequestsAfterTimeout(allFutures); if (interrupted) { Thread.currentThread().interrupt(); } if (receivedResponses.hasQuorum()) { encounteredErrors.forEach(throwable -> log.warn(PAXOS_MESSAGE_ERROR, throwable)); } } return receivedResponses; }

Target:
private static <SERVICE, RESPONSE extends PaxosResponse> PaxosResponses<RESPONSE> collectResponses( ImmutableList<SERVICE> remotes, final Function<SERVICE, RESPONSE> request, int quorumSize, Map<SERVICE, ExecutorService> executors, Duration remoteRequestTimeout, boolean shortcircuitIfQuorumImpossible) { MultiplexingCompletionService<SERVICE, RESPONSE> responseCompletionService = MultiplexingCompletionService.create(executors); List<Future<RESPONSE>> allFutures = Lists.newArrayList(); for (final SERVICE remote : remotes) { try { allFutures.add(responseCompletionService.submit(remote, () -> request.apply(remote))); } catch (RejectedExecutionException e) { requestExecutionRejection.mark(); if (shouldLogDiagnosticInformation()) { log.info("Quorum checker executor rejected task", e); log.info("Rate of execution rejections: {}", SafeArg.of("rate1m", requestExecutionRejection.getOneMinuteRate())); } } } List<Throwable> encounteredErrors = Lists.newArrayList(); boolean interrupted = false; PaxosResponses<RESPONSE> receivedResponses = new PaxosResponses<>(remotes.size(), quorumSize, shortcircuitIfQuorumImpossible); try { long deadline = System.nanoTime() + remoteRequestTimeout.toNanos(); while (receivedResponses.hasMoreRequests() && receivedResponses.shouldProcessNextRequest()) { try { Future<RESPONSE> responseFuture = responseCompletionService.poll( deadline - System.nanoTime(), TimeUnit.NANOSECONDS); if (timedOut(responseFuture)) { break; } receivedResponses.add(responseFuture.get()); } catch (ExecutionException e) { receivedResponses.markFailure(); encounteredErrors.add(e.getCause()); } } } catch (InterruptedException e) { log.warn("paxos request interrupted", e); interrupted = true; } finally { cancelOutstandingRequestsAfterTimeout(allFutures); if (interrupted) { Thread.currentThread().interrupt(); } if (!receivedResponses.hasQuorum()) { encounteredErrors.forEach(throwable -> log.warn(PAXOS_MESSAGE_ERROR, throwable)); } } return receivedResponses; }