private void pollQuotaCompliantRequests(List<RequestInfo> requestsToSend,
      Map<QuotaResource, LinkedList<RequestInfo>> requestQueue) {
    Timer.Context timer = routerMetrics.pollQuotaCompliantRequestTime.time();
    Iterator<Map.Entry<QuotaResource, LinkedList<RequestInfo>>> requestQueueIterator =
        requestQueue.entrySet().iterator();
    while (requestQueueIterator.hasNext()) {
      QuotaResource quotaResource = requestQueueIterator.next().getKey();
      if (quotaResource.equals(UNKNOWN_QUOTA_RESOURCE)) {
        // If there are requests for which QuotaResource couldn't be found, this is most likely a bug.
        // As a temporary hack, we will consider all those requests to be quota compliant.
        requestsToSend.addAll(requestQueue.get(UNKNOWN_QUOTA_RESOURCE));
        requestQueueIterator.remove();
        continue;
      }
      boolean quotaAvailable = true;
      while (!requestQueue.get(quotaResource).isEmpty() && quotaAvailable) {
        RequestInfo requestInfo = requestQueue.get(quotaResource).getFirst();
        QuotaAction recommendedQuotaAction = requestInfo.getChargeable().checkAndCharge(false);
        switch (recommendedQuotaAction) {
          case ALLOW:
            requestsToSend.add(requestInfo);
            requestQueue.get(quotaResource).removeFirst();
            break;
          case DELAY:
            quotaAvailable = false;
            break;
          case REJECT:
            quotaAvailable = false;
            logger.warn("Rejecting request for quota resource {} because of reject recommendation.",
                quotaResource.toString());
            routerMetrics.rejectedRequestRate.mark();
            nonCompliantRequests.add(requestInfo);
            requestQueue.get(quotaResource).removeFirst();
            break;
        }
      }
      if (requestQueue.get(quotaResource).isEmpty()) {
        requestQueueIterator.remove();
      }
    }
    timer.stop();
  }
Drain the request queue based on resource quota only and update the requests to be sent to {@code requestsToSend}.
@param requestsToSend a list of {@link RequestInfo} that will contain the requests to be sent out.
@param requestQueue {@link Map} of {@link QuotaResource} to {@link List} of {@link RequestInfo} from which the requests to be sent will be polled.
ambry-router/src/main/java/com/github/ambry/router/QuotaAwareOperationController.java