@Override
  public QuotaAction checkAndCharge(boolean shouldCheckQuotaExceedAllowed, boolean forceCharge, long chunkSize) throws QuotaException {
    QuotaAction quotaAction = QuotaAction.ALLOW;
    try {
      Map<QuotaName, Double> requestCost = requestCostPolicy.calculateRequestQuotaCharge(restRequest, chunkSize)
          .entrySet()
          .stream()
          .collect(Collectors.toMap(entry -> QuotaName.valueOf(entry.getKey()), Map.Entry::getValue));
      quotaAction =
          quotaManager.chargeAndRecommend(restRequest, requestCost, shouldCheckQuotaExceedAllowed, forceCharge);
      if (isQuotaEnforcedOnRequest && QuotaUtils.shouldThrottle(quotaAction)) {
        if (quotaManager.getQuotaMode() == QuotaMode.THROTTLING) {
          throw new QuotaException("Exception while charging quota",
              new RouterException("RequestQuotaExceeded", RouterErrorCode.TooManyRequests), false);
        } else {
          LOGGER.debug("Quota exceeded for an in progress request.");
        }
      }
    } catch (Exception ex) {
      if (ex.getCause() instanceof RouterException && ((RouterException) ex.getCause()).getErrorCode()
          .equals(RouterErrorCode.TooManyRequests)) {
        throw ex;
      }
      LOGGER.error("Unexpected exception while charging quota.", ex);
    }
    return quotaAction;
  }
Constructor for {@link PostProcessQuotaChargeCallback}.
@param quotaManager {@link QuotaManager} object responsible for charging the quota.
@param restRequest {@link RestRequest} for which quota is being charged.
@param isQuotaEnforcedOnRequest flag indicating if request quota should be enforced after charging. Requests like
                                update ttl, delete etc are charged, but quota is not enforced on them.
ambry-quota/src/main/java/com/github/ambry/quota/PostProcessQuotaChargeCallback.java