Class 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 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 be null).
        throttlingRatePolicy - the datasource where to lookup for the rate to apply (must not be null).
        throttlingStrategy - the throttling strategy to apply.
    • 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:
        filter in interface org.forgerock.http.Filter