Change long to int, tidy up error msg

This commit is contained in:
ghubstan 2020-12-17 14:12:04 -03:00
parent 2148a4d958
commit 89e2187878
No known key found for this signature in database
GPG Key ID: E35592D6800A861E
2 changed files with 7 additions and 5 deletions

View File

@ -84,11 +84,13 @@ public final class CallRateMeteringInterceptor implements ServerInterceptor {
GrpcCallRateMeter rateMeter) {
// The derived method name may not be an exact match to CLI's method name.
String timeUnitName = StringUtils.chop(rateMeter.getTimeUnit().name().toLowerCase());
return format("the maximum allowed number of %s calls (%d/%s) has been exceeded by %d calls",
int callCountAboveLimit = rateMeter.getCallsCount() - rateMeter.getAllowedCallsPerTimeUnit();
return format("the maximum allowed number of %s calls (%d/%s) has been exceeded by %d call%s",
methodName.toLowerCase(),
rateMeter.getAllowedCallsPerTimeUnit(),
timeUnitName,
rateMeter.getCallsCount() - rateMeter.getAllowedCallsPerTimeUnit());
callCountAboveLimit,
callCountAboveLimit == 1 ? "" : "s");
}
private Optional<Map.Entry<String, GrpcCallRateMeter>> getRateMeterKV(ServerCall<?, ?> serverCall) {

View File

@ -18,12 +18,12 @@ import static java.lang.String.format;
public final class GrpcCallRateMeter {
@Getter
private final long allowedCallsPerTimeUnit;
private final int allowedCallsPerTimeUnit;
@Getter
private final TimeUnit timeUnit;
@Getter
private long callsCount = 0;
private int callsCount = 0;
@Getter
private boolean isRunning;
@ -31,7 +31,7 @@ public final class GrpcCallRateMeter {
@Nullable
private Timer timer;
public GrpcCallRateMeter(long allowedCallsPerTimeUnit, TimeUnit timeUnit) {
public GrpcCallRateMeter(int allowedCallsPerTimeUnit, TimeUnit timeUnit) {
this.allowedCallsPerTimeUnit = allowedCallsPerTimeUnit;
this.timeUnit = timeUnit;
}