/** * Throttle a request with a key argument if necessary. * @param key key used for the table request */ public void throttle(K key) { throttle(getCredits(key, null)); }
/** * Throttle a request with a collection of keys as the argument if necessary. * @param keys collection of keys used for the table request */ public void throttle(Collection<K> keys) { throttle(getCredits(keys)); }
/** * Throttle a request with a collection of keys as the argument if necessary. * @param keys collection of keys used for the table request */ public void throttle(Collection<K> keys) { throttle(getCredits(keys)); }
/** * Throttle a request with a collection of table records as the argument if necessary. * @param records collection of records used for the table request */ public void throttleRecords(Collection<Entry<K, V>> records) { throttle(getEntryCredits(records)); } }
/** * Throttle a request with both the key and value arguments if necessary. * @param key key used for the table request * @param value value used for the table request */ public void throttle(K key, V value) { throttle(getCredits(key, value)); }
/** * Throttle a request with a key argument if necessary. * @param key key used for the table request */ public void throttle(K key) { throttle(getCredits(key, null)); }
/** * Throttle a request with a collection of table records as the argument if necessary. * @param records collection of records used for the table request */ public void throttleRecords(Collection<Entry<K, V>> records) { throttle(getEntryCredits(records)); }
/** * Throttle a request with a key argument if necessary. * @param key key used for the table request */ public void throttle(K key) { throttle(getCredits(key, null)); }
/** * Throttle a request with both the key and value arguments if necessary. * @param key key used for the table request * @param value value used for the table request */ public void throttle(K key, V value) { throttle(getCredits(key, value)); }
/** * Throttle a request with a key argument if necessary. * @param key key used for the table request */ public void throttle(K key) { throttle(getCredits(key, null)); }
/** * Throttle a request with both the key and value arguments if necessary. * @param key key used for the table request * @param value value used for the table request */ public void throttle(K key, V value) { throttle(getCredits(key, value)); }
/** * Throttle a request with a collection of keys as the argument if necessary. * @param keys collection of keys used for the table request */ public void throttle(Collection<K> keys) { throttle(getCredits(keys)); }
/** * Throttle a request with both the key and value arguments if necessary. * @param key key used for the table request * @param value value used for the table request */ public void throttle(K key, V value) { throttle(getCredits(key, value)); }
@Override public CompletableFuture<Map<K, V>> getAllAsync(List<K> keys) { return isReadRateLimited() ? CompletableFuture .runAsync(() -> readRateLimiter.throttle(keys), rateLimitingExecutor) .thenCompose((r) -> table.getAllAsync(keys)) : table.getAllAsync(keys); }
@Override public CompletableFuture<Void> putAsync(K key, V value) { return isWriteRateLimited() ? CompletableFuture .runAsync(() -> writeRateLimiter.throttle(key, value), rateLimitingExecutor) .thenCompose((r) -> table.putAsync(key, value)) : table.putAsync(key, value); }
@Override public CompletableFuture<Void> deleteAsync(K key) { return isWriteRateLimited() ? CompletableFuture .runAsync(() -> writeRateLimiter.throttle(key), rateLimitingExecutor) .thenCompose((r) -> table.deleteAsync(key)) : table.deleteAsync(key); }
@Override public CompletableFuture<V> getAsync(K key) { return isReadRateLimited() ? CompletableFuture .runAsync(() -> readRateLimiter.throttle(key), rateLimitingExecutor) .thenCompose((r) -> table.getAsync(key)) : table.getAsync(key); }
@Override public CompletableFuture<Void> deleteAllAsync(List<K> keys) { return isWriteRateLimited() ? CompletableFuture .runAsync(() -> writeRateLimiter.throttle(keys), rateLimitingExecutor) .thenCompose((r) -> table.deleteAllAsync(keys)) : table.deleteAllAsync(keys); }
@Test public void testThrottleUnknownTag() { TableRateLimiter<String, String> rateLimitHelper = getThrottler("unknown_tag"); rateLimitHelper.throttle("foo"); verify(rateLimitHelper.rateLimiter, times(0)).acquire(anyInt()); verify(rateLimitHelper.rateLimiter, times(1)).acquire(anyMap()); } }
@Test public void testThrottle() { TableRateLimiter<String, String> rateLimitHelper = getThrottler(); Timer timer = mock(Timer.class); rateLimitHelper.setTimerMetric(timer); rateLimitHelper.throttle("foo"); verify(rateLimitHelper.rateLimiter, times(1)).acquire(anyMap()); verify(timer, times(1)).update(anyLong()); }