S - the type of state used by child classes to track the clients.@ThreadSafe public abstract class Throttler<S> extends Object
| Modifier and Type | Field and Description |
|---|---|
String |
alwaysThrottleParam
This parameter in query will cause throttling no matter what.
|
| Constructor and Description |
|---|
Throttler(Callable<S> createThrottlingState,
com.google.common.cache.Cache<Object,S> stateStore,
String enableThrottlingIfHeader,
String alwaysThrottleParam,
Clock clock)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected S |
getState(Object bucket) |
protected S |
getStateIfPresent(Object bucket) |
protected abstract Instant |
internalThrottledUntil(Object bucket,
javax.servlet.http.HttpServletRequest request)
Implemented by clients for the specific throttling logic.
|
protected boolean |
shouldBypassThrottling(javax.servlet.http.HttpServletRequest request)
Check whether this request should have throttling enabled.
|
Duration |
throttledDuration(Object bucket,
javax.servlet.http.HttpServletRequest request) |
Instant |
throttledUntil(Object bucket,
javax.servlet.http.HttpServletRequest request)
Until when is this request throttled.
|
public Throttler(Callable<S> createThrottlingState, com.google.common.cache.Cache<Object,S> stateStore, String enableThrottlingIfHeader, String alwaysThrottleParam, @Nonnull Clock clock)
createThrottlingState - how to create the initial throttling state
when we start tracking a specific clientstateStore - the cache in which we store the per client state of
throttlingenableThrottlingIfHeader - throttling is only enabled if this header is presentalwaysThrottleParam - this query parameter will cause throttling no matter whatclock - protected S getState(Object bucket) throws ExecutionException
ExecutionExceptionprotected boolean shouldBypassThrottling(javax.servlet.http.HttpServletRequest request)
public Instant throttledUntil(Object bucket, javax.servlet.http.HttpServletRequest request)
public Duration throttledDuration(Object bucket, javax.servlet.http.HttpServletRequest request)
Copyright © 2019. All rights reserved.