Class ThrottlingFilter
- java.lang.Object
-
- org.forgerock.http.filter.throttling.ThrottlingFilter
-
- All Implemented Interfaces:
org.forgerock.http.Filter
public class ThrottlingFilter extends Object implements org.forgerock.http.Filter
This filter applies a rate limitation to incoming requests : over the limit requests will be rejected with a 429 (Too Many Requests) response, others will pass through. The rate limiting is implemented as a token bucket strategy that gives us the ability to handle rate limits through a sliding window. Multiple rates can be supported in parallel with the support of a partition key (we first try to find the bucket to use for each incoming request, then we apply the rate limit). Note that if no rate definition is found, this filter let the request goes through.
-
-
Constructor Summary
Constructors Constructor Description ThrottlingFilter(String name, org.forgerock.util.AsyncFunction<ContextAndRequest,String,Exception> requestGroupingPolicy, ThrottlingPolicy throttlingRatePolicy, ThrottlingStrategy throttlingStrategy)ThrottlingFilter(org.forgerock.util.AsyncFunction<ContextAndRequest,String,Exception> requestGroupingPolicy, ThrottlingPolicy throttlingRatePolicy, ThrottlingStrategy throttlingStrategy)Constructs a ThrottlingFilter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.forgerock.util.promise.Promise<org.forgerock.http.protocol.Response,org.forgerock.util.promise.NeverThrowsException>filter(org.forgerock.services.context.Context context, org.forgerock.http.protocol.Request request, org.forgerock.http.Handler next)voidstop()Stops this filter and frees the resources.
-
-
-
Constructor Detail
-
ThrottlingFilter
public ThrottlingFilter(org.forgerock.util.AsyncFunction<ContextAndRequest,String,Exception> requestGroupingPolicy, ThrottlingPolicy throttlingRatePolicy, ThrottlingStrategy throttlingStrategy)
Constructs a ThrottlingFilter.- Parameters:
requestGroupingPolicy- the key used to identify the token bucket (must not benull).throttlingRatePolicy- the datasource where to lookup for the rate to apply (must not benull).throttlingStrategy- the throttling strategy to apply.
-
ThrottlingFilter
public ThrottlingFilter(String name, org.forgerock.util.AsyncFunction<ContextAndRequest,String,Exception> requestGroupingPolicy, ThrottlingPolicy throttlingRatePolicy, ThrottlingStrategy throttlingStrategy)
-
-
Method Detail
-
stop
public void stop()
Stops this filter and frees the resources.
-
filter
public org.forgerock.util.promise.Promise<org.forgerock.http.protocol.Response,org.forgerock.util.promise.NeverThrowsException> filter(org.forgerock.services.context.Context context, org.forgerock.http.protocol.Request request, org.forgerock.http.Handler next)- Specified by:
filterin interfaceorg.forgerock.http.Filter
-
-