Source:
<code>public void execute() throws CoordinatorException { logger.debug("{} operation beginning execute", oc); sendRequests(); while (true) { try { OperationResponse operationResponse = responseQueue.poll(operationExpirationMs - SystemTime.getInstance().milliseconds(), TimeUnit.MILLISECONDS); logger.debug("{} operation processing a response", oc); if (operationResponse == null) { throw new CoordinatorException("Operation timed out.", CoordinatorError.OperationTimedOut); } ReplicaId replicaId = operationResponse.getReplicaId(); Response response = operationResponse.getResponse(); if (!requestsInFlight.remove(replicaId)) { throw new CoordinatorException("Response received from replica to which no request is in flight. ReplicaId:" + " " + replicaId, CoordinatorError.UnexpectedInternalError); } if (response != null) { if (processResponseError(replicaId, response.getError())) { operationPolicy.successfulResponse(replicaId); } else { operationPolicy.failedResponse(replicaId); } } else { operationPolicy.failedResponse(replicaId); } <START> if (operationPolicy.isDone()) { <END> operationComplete.set(true); logger.debug("{} operation completing execute normally", oc); return; } sendRequests(); } catch (CoordinatorException e) { operationComplete.set(true); logger.debug("{} operation throwing CoordinatorException to complete execute ({}).", oc, e.getErrorCode()); throw e; } catch (InterruptedException e) { operationComplete.set(true); logger.info("{} operation interrupted during execute.", oc); throw new CoordinatorException("Operation interrupted.", CoordinatorError.Interrupted); } } }</code><technical_language>useful rename this method explicitly exit condition for this loop</technical_language>

Target:
public void execute() throws CoordinatorException { logger.debug("{} operation beginning execute", context); sendRequests(); while (true) { try { OperationResponse operationResponse = responseQueue.poll(operationExpirationMs - SystemTime.getInstance().milliseconds(), TimeUnit.MILLISECONDS); logger.debug("{} operation processing a response", context); if (operationResponse == null) { throw new CoordinatorException("Operation timed out.", CoordinatorError.OperationTimedOut); } ReplicaId replicaId = operationResponse.getReplicaId(); if (!requestsInFlight.remove(replicaId)) { CoordinatorException e = new CoordinatorException("Coordinator received unexpected response", CoordinatorError.UnexpectedInternalError); logger.error("Response received from replica ({}) to which no request is in flight: {}", replicaId, e); throw e; } if (operationResponse.getError() == RequestResponseError.SUCCESS) { if (processResponseError(replicaId, operationResponse.getResponse().getError())) { operationPolicy.onSuccessfulResponse(replicaId); } else { operationPolicy.onFailedResponse(replicaId); } } else { operationPolicy.onFailedResponse(replicaId); } if (operationPolicy.isComplete()) { operationComplete.set(true); logger.debug("{} operation successfully completing execute", context); return; } if (!operationPolicy.mayComplete()) { throw new CoordinatorException("Insufficient DataNodes replied to complete operation", CoordinatorError.AmbryUnavailable); } sendRequests(); } catch (CoordinatorException e) { operationComplete.set(true); logger.debug("{} operation throwing CoordinatorException during ({}).", context, e.getErrorCode()); throw e; } catch (InterruptedException e) { operationComplete.set(true); logger.info("{} operation interrupted during execute", context); throw new CoordinatorException("Operation interrupted.", CoordinatorError.UnexpectedInternalError); } } }