Class ServletLimiterBuilder


  • public final class ServletLimiterBuilder
    extends com.netflix.concurrency.limits.limiter.AbstractPartitionedLimiter.Builder<ServletLimiterBuilder,​jakarta.servlet.http.HttpServletRequest>
    Builder to simplify creating a Limiter specific to a Servlet filter. By default, the same concurrency limit is shared by all requests. The limiter can be partitioned based on one of many request attributes. Only one type of partition may be specified.
    • Constructor Detail

      • ServletLimiterBuilder

        public ServletLimiterBuilder()
    • Method Detail

      • partitionByHeader

        public ServletLimiterBuilder partitionByHeader​(java.lang.String name)
        Partition the limit by header
        Returns:
        Chainable builder
      • partitionByUserPrincipal

        public ServletLimiterBuilder partitionByUserPrincipal​(java.util.function.Function<java.security.Principal,​java.lang.String> principalToGroup)
        Partition the limit by Principal. Percentages of the limit are partitioned to named groups. Group membership is derived from the provided mapping function.
        Parameters:
        principalToGroup - Mapping function from Principal to a named group.
        Returns:
        Chainable builder
      • partitionByAttribute

        public ServletLimiterBuilder partitionByAttribute​(java.lang.String name)
        Partition the limit by request attribute
        Returns:
        Chainable builder
      • partitionByParameter

        public ServletLimiterBuilder partitionByParameter​(java.lang.String name)
        Partition the limit by request parameter
        Returns:
        Chainable builder
      • partitionByPathInfo

        public ServletLimiterBuilder partitionByPathInfo​(java.util.function.Function<java.lang.String,​java.lang.String> pathToGroup)
        Partition the limit by the full path. Percentages of the limit are partitioned to named groups. Group membership is derived from the provided mapping function.
        Parameters:
        pathToGroup - Mapping function from full path to a named group.
        Returns:
        Chainable builder
      • bypassLimitResolver

        public ServletLimiterBuilder bypassLimitResolver​(java.util.function.Predicate<jakarta.servlet.http.HttpServletRequest> shouldBypass)
        Add a chainable bypass resolver predicate from context. Multiple resolvers may be added and if any of the predicate condition returns true the call is bypassed without increasing the limiter inflight count and affecting the algorithm. Will not bypass any calls by default if no resolvers are added.
        Parameters:
        shouldBypass - Predicate condition to bypass limit
        Returns:
        Chainable builder
      • bypassLimitByHeader

        public ServletLimiterBuilder bypassLimitByHeader​(java.lang.String name,
                                                         java.lang.String value)
        Bypass limit if the value of the provided header name matches the specified value.
        Parameters:
        name - The name of the header to check. This should match exactly with the header name in the HttpServletRequest context.
        value - The value to compare against. If the value of the header in the context matches this value, the limit will be bypassed.
        Returns:
        Chainable builder
      • bypassLimitByAttribute

        public ServletLimiterBuilder bypassLimitByAttribute​(java.lang.String name,
                                                            java.lang.String value)
        Bypass limit if the value of the provided attribute name matches the specified value.
        Parameters:
        name - The name of the attribute to check. This should match exactly with the attribute name in the HttpServletRequest context.
        value - The value to compare against. If the value of the attribute in the context matches this value, the limit will be bypassed.
        Returns:
        Chainable builder
      • bypassLimitByParameter

        public ServletLimiterBuilder bypassLimitByParameter​(java.lang.String name,
                                                            java.lang.String value)
        Bypass limit if the value of the provided parameter name matches the specified value.
        Parameters:
        name - The name of the parameter to check. This should match exactly with the parameter name in the HttpServletRequest context.
        value - The value to compare against. If the value of the parameter in the context matches this value, the limit will be bypassed.
        Returns:
        Chainable builder
      • bypassLimitByPathInfo

        public ServletLimiterBuilder bypassLimitByPathInfo​(java.lang.String pathInfo)
        Bypass limit if the request path info matches the specified path.
        Parameters:
        pathInfo - The path info to check against the HttpServletRequest pathInfo. If the request's pathInfo matches this, the limit will be bypassed.
        Returns:
        Chainable builder
      • bypassLimitByMethod

        public ServletLimiterBuilder bypassLimitByMethod​(java.lang.String method)
        Bypass limit if the request method matches the specified method.
        Parameters:
        method - The HTTP method (e.g. GET, POST, or PUT) to check against the HttpServletRequest method. If the request's method matches this method, the limit will be bypassed.
        Returns:
        Chainable builder