@Test public void finishedFutureReturnedIfPermitsAreGranted() { BufferedRateLimiter limiter = new BufferedRateLimiter(10, 10, 100); ListenableFuture<Void> actual = limiter.acquireAsync(); assertTrue(actual.isDone()); }
@Override public ListenableFuture<Void> acquireAsync() { totalRequested.incrementAndGet(); if (queue.isEmpty()) { if (permits.incrementAndGet() <= permitsLimit) { if (permits.get() > maxGrantedPermissions.get()) { maxGrantedPermissions.set(permits.get()); } totalGranted.incrementAndGet(); return Futures.immediateFuture(null); } permits.decrementAndGet(); } return putInQueue(); }
BufferedRateLimiter implements AsyncRateLimiter { @Override public ListenableFuture<Void> acquireAsync() { totalRequested.incrementAndGet(); if (queue.isEmpty()) { if (permits.incrementAndGet() <= permitsLimit) { if (permits.get() > maxGrantedPermissions.get()) { maxGrantedPermissions.set(permits.get()); } totalGranted.incrementAndGet(); return Futures.immediateFuture(null); } permits.decrementAndGet(); } return putInQueue(); } }
BufferedRateLimiter implements AsyncRateLimiter { @Override public ListenableFuture<Void> acquireAsync() { totalRequested.incrementAndGet(); if (queue.isEmpty()) { if (permits.incrementAndGet() <= permitsLimit) { if (permits.get() > maxGrantedPermissions.get()) { maxGrantedPermissions.set(permits.get()); } totalGranted.incrementAndGet(); return Futures.immediateFuture(null); } permits.decrementAndGet(); } return putInQueue(); } BufferedRateLimiter(@Value("${cassandra.query.buffer_size}") int queueLimit,
                               @Value("${cassandra.query.concurrent_limit}") int permitsLimit,
                               @Value("${cassandra.query.permit_max_wait_time}") int maxPermitWaitTime); }
BufferedRateLimiter implements AsyncRateLimiter { @Override public ListenableFuture<Void> acquireAsync() { totalRequested.incrementAndGet(); if (queue.isEmpty()) { if (permits.incrementAndGet() <= permitsLimit) { if (permits.get() > maxGrantedPermissions.get()) { maxGrantedPermissions.set(permits.get()); } totalGranted.incrementAndGet(); return Futures.immediateFuture(null); } permits.decrementAndGet(); } return putInQueue(); } BufferedRateLimiter(@Value("${cassandra.query.buffer_size}") int queueLimit,
                               @Value("${cassandra.query.concurrent_limit}") int permitsLimit,
                               @Value("${cassandra.query.permit_max_wait_time}") int maxPermitWaitTime); @Override ListenableFuture<Void> acquireAsync(); @Override void release(); @Scheduled(fixedDelayString = "${cassandra.query.rate_limit_print_interval_ms}") void printStats(); }
BufferedRateLimiter implements AsyncRateLimiter { @Override public ListenableFuture<Void> acquireAsync() { totalRequested.incrementAndGet(); if (queue.isEmpty()) { if (permits.incrementAndGet() <= permitsLimit) { if (permits.get() > maxGrantedPermissions.get()) { maxGrantedPermissions.set(permits.get()); } totalGranted.incrementAndGet(); return Futures.immediateFuture(null); } permits.decrementAndGet(); } return putInQueue(); } BufferedRateLimiter(@Value("${cassandra.query.buffer_size}") int queueLimit,
                               @Value("${cassandra.query.concurrent_limit}") int permitsLimit,
                               @Value("${cassandra.query.permit_max_wait_time}") int maxPermitWaitTime); @Override ListenableFuture<Void> acquireAsync(); @Override void release(); @Scheduled(fixedDelayString = "${cassandra.query.rate_limit_print_interval_ms}") void printStats();  }