Package io.muserver

Class RateLimitBuilder

    • Constructor Detail

      • RateLimitBuilder

        public RateLimitBuilder()
    • Method Detail

      • withRate

        public RateLimitBuilder withRate​(long rate)
        Sets the allowed rate. For example, this would be 10 if you allowed 10 per second.
        Parameters:
        rate - The rate to use for this bucket
        Returns:
        This builder
        Throws:
        java.lang.IllegalArgumentException - if the parameter is 0 or negative.
      • withWindow

        public RateLimitBuilder withWindow​(long period,
                                           java.util.concurrent.TimeUnit unit)
        The period that the limit applies to. For example, this would be 1 second if you allowed 10 per 1 second. The default is 1 second.
        Parameters:
        period - The time period of the limit.
        unit - The unit of the period
        Returns:
        This builder.
        Throws:
        java.lang.IllegalArgumentException - if period is less than 1, or unit is null.
      • withBucket

        public RateLimitBuilder withBucket​(java.lang.String name)
        Sets the bucket that the limit applies to.
        Parameters:
        name - The bucket, for example when limiting by IP address this would be an IP address.
        Returns:
        This builder.
      • withRejectionAction

        public RateLimitBuilder withRejectionAction​(RateLimitRejectionAction action)
        Specifies what to do when this limit is breached.
        Parameters:
        action - The action to take
        Returns:
        This builder
        Throws:
        java.lang.IllegalArgumentException - If the action is null
      • rateLimit

        public static RateLimitBuilder rateLimit()
        Creates a new builder
        Returns:
        A new rate limit builder
      • build

        public RateLimit build()
        Creates the rate limit from the builder
        Returns:
        a new Rate Limit