/** * Acquires permits from this {@link RateLimiter} if it can be acquired immediately without delay. * * <p> * This method is equivalent to {@code tryAcquire(1)}. * * @param permits * the number of permits to acquire * @return {@code true} if the permits were acquired, {@code false} otherwise */ public synchronized boolean tryAcquire() { return tryAcquire(1); }
/** * Acquires permits from this {@link RateLimiter} if it can be acquired immediately without delay. * * <p> * This method is equivalent to {@code tryAcquire(1)}. * * @param permits * the number of permits to acquire * @return {@code true} if the permits were acquired, {@code false} otherwise */ public synchronized boolean tryAcquire() { return tryAcquire(1); }
/** * It acquires msg and bytes permits from rate-limiter and returns if acquired permits succeed. * * @param msgPermits * @param bytePermits * @return */ public boolean tryDispatchPermit(long msgPermits, long bytePermits) { boolean acquiredMsgPermit = msgPermits <= 0 || dispatchRateLimiterOnMessage == null // acquiring permits must be < configured msg-rate; || dispatchRateLimiterOnMessage.tryAcquire(msgPermits); boolean acquiredBytePermit = bytePermits <= 0 || dispatchRateLimiterOnByte == null // acquiring permits must be < configured msg-rate; || dispatchRateLimiterOnByte.tryAcquire(bytePermits); return acquiredMsgPermit && acquiredBytePermit; }