if (bytes > 0) {
// throttling based on bytes, so see if would be blocked
permit = bpsLimiter.tryAcquire(bytes, timeout, unit);
}
if (msgs > 0 && !permit) {
// throttling based on messages, and would be throttled based on bytes,
// check if would be throttled based on messages, setting permit to true if not being
// throttled based on messages
permit = permit || mpsLimiter.tryAcquire(msgs, timeout, unit);
} else if (msgs > 0) {
// If we reach here, either not throttling based on bytes, or have
// not exceeded byte rate, but throttling based on messages.
// *** We are not saving return of tryAcquire, so whether or not
// we would have been throttled, it returns default value of
// permit (true). Think it should be: permit = mpsLimiter.tryAcquire(msgs);
mpsLimiter.tryAcquire(msgs);
}
if (!isEnabled() || (msgs == 0 && bytes == 0)) {
return 0;
}
delayTimeSec = (bytes > 0 ? bpsLimiter.acquire(bytes) : 0);
delayTimeSec += (msgs > 0 ? mpsLimiter.acquire(msgs) : 0);