public class ThrottlingFilter extends Object implements javax.servlet.Filter
Retry-After HTTP header giving a backoff
time in seconds.
The clients are segmented in different buckets and resource consumption is
tracked individually for each of those buckets. The segmentation is done by
[IP address, User Agent], but could be extended to support more complex
strategies. A bucket is only kept while its client is active. After a period
of inactivity, the bucket is deleted.
All state is limited to a single JVM, this filter is not cluster aware.| Constructor and Description |
|---|
ThrottlingFilter() |
| Modifier and Type | Method and Description |
|---|---|
static Callable<ThrottlingState> |
createThrottlingState(int timeBucketCapacityInSeconds,
int timeBucketRefillAmountInSeconds,
int timeBucketRefillPeriodInMinutes,
int errorBucketCapacity,
int errorBucketRefillAmount,
int errorBucketRefillPeriodInMinutes)
Create Callable to initialize throttling state.
|
void |
destroy() |
void |
doFilter(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
javax.servlet.FilterChain chain)
Check resource consumption and throttle requests as needed.
|
void |
init(javax.servlet.FilterConfig filterConfig)
Initialise the filter.
|
public void init(javax.servlet.FilterConfig filterConfig)
throws javax.servlet.ServletException
loadStringParam(String, FilterConfig) for
the details of where the configuration is loaded from.init in interface javax.servlet.FilterfilterConfig - javax.servlet.ServletExceptionpublic static Callable<ThrottlingState> createThrottlingState(int timeBucketCapacityInSeconds, int timeBucketRefillAmountInSeconds, int timeBucketRefillPeriodInMinutes, int errorBucketCapacity, int errorBucketRefillAmount, int errorBucketRefillPeriodInMinutes)
timeBucketCapacityInSeconds - timeBucketRefillAmountInSeconds - timeBucketRefillPeriodInMinutes - errorBucketCapacity - errorBucketRefillAmount - errorBucketRefillPeriodInMinutes - public void doFilter(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
javax.servlet.FilterChain chain)
throws IOException,
javax.servlet.ServletException
doFilter in interface javax.servlet.Filterrequest - response - chain - IOExceptionjavax.servlet.ServletExceptionpublic void destroy()
destroy in interface javax.servlet.FilterCopyright © 2017. All rights reserved.