in src/main/java/com/googlesource/gerrit/plugins/quota/AccountLimitsConfig.java [104:158]
void parseRateLimit(Config c, String groupName, Type type) {
String name = type.toConfigValue();
String value = c.getString(GROUP_SECTION, groupName, name);
if (value == null) {
return;
}
value = value.trim();
Matcher m = PATTERN.matcher(value);
if (!m.matches()) {
log.error(
"Invalid ''{}'' ratelimit configuration ''{}''; ignoring the configuration entry",
name,
value);
return;
}
String digits = m.group(1);
String unitName = m.group(2).trim();
String storeCountString = m.group(3).trim();
long burstCount;
try {
burstCount = Long.parseLong(storeCountString);
} catch (NumberFormatException e) {
log.error(
"Invalid ''{}'' ratelimit store configuration ''{}''; ignoring the configuration entry",
name,
storeCountString);
return;
}
TimeUnit inputUnit = TimeUnit.HOURS;
double ratePerSecond;
if (match(unitName, "s", "sec", "second")) {
inputUnit = TimeUnit.SECONDS;
} else if (match(unitName, "m", "min", "minute")) {
inputUnit = TimeUnit.MINUTES;
} else if (match(unitName, "h", "hr", "hour") || unitName.isEmpty()) {
inputUnit = TimeUnit.HOURS;
} else if (match(unitName, "d", "day")) {
inputUnit = TimeUnit.DAYS;
} else {
logNotRateUnit(GROUP_SECTION, groupName, name, value);
return;
}
try {
ratePerSecond = 1.0D * Long.parseLong(digits) / TimeUnit.SECONDS.convert(1, inputUnit);
} catch (NumberFormatException nfe) {
logNotRateUnit(GROUP_SECTION, groupName, unitName, value);
return;
}
int maxBurstSeconds = (int) (burstCount / ratePerSecond);
rateLimits.put(type, groupName, new RateLimit(type, ratePerSecond, maxBurstSeconds));
}