Class ThrottlingFilter
java.lang.Object
org.forgerock.openig.filter.throttling.ThrottlingFilter
- All Implemented Interfaces:
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
ConstructorsConstructorDescriptionThrottlingFilter
(AsyncFunction<ContextAndRequest, String, Exception> requestGroupingPolicy, ThrottlingPolicy throttlingRatePolicy, ThrottlingStrategy throttlingStrategy) Constructs a ThrottlingFilter. -
Method Summary
-
Constructor Details
-
ThrottlingFilter
public ThrottlingFilter(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.
-
-
Method Details
-
stop
public void stop()Stops this filter and frees the resources. -
filter
public Promise<Response,NeverThrowsException> filter(Context context, Request request, Handler next) Description copied from interface:Filter
Filters the request and/or response of an exchange. To pass the request to the next filter or handler in the chain, the filter callsnext.handle(context, request)
.This method may elect not to pass the request to the next filter or handler, and instead handle the request itself. It can achieve this by merely avoiding a call to
next.handle(context, request)
and creating its own response object. The filter is also at liberty to replace a response with another of its own by intercepting the response returned by the next handler.
-