public class RateLimitBuilder extends Object
RateLimit
objects. The built limit is returned by a RateLimitSelector
.
See MuServerBuilder.withRateLimiter(RateLimitSelector)
for more details on how to use this.Constructor and Description |
---|
RateLimitBuilder() |
Modifier and Type | Method and Description |
---|---|
RateLimit |
build()
Creates the rate limit from the builder
|
static RateLimitBuilder |
rateLimit()
Creates a new builder
|
RateLimitBuilder |
withBucket(String name)
Sets the bucket that the limit applies to.
|
RateLimitBuilder |
withRate(long rate)
Sets the allowed rate.
|
RateLimitBuilder |
withRejectionAction(RateLimitRejectionAction action)
Specifies what to do when this limit is breached.
|
RateLimitBuilder |
withWindow(long period,
TimeUnit unit)
The period that the limit applies to.
|
public RateLimitBuilder withRate(long rate)
rate
- The rate to use for this bucketIllegalArgumentException
- if the parameter is 0 or negative.public RateLimitBuilder withWindow(long period, TimeUnit unit)
period
- The time period of the limit.unit
- The unit of the periodIllegalArgumentException
- if period is less than 1, or unit is null.public RateLimitBuilder withBucket(String name)
name
- The bucket, for example when limiting by IP address this would be an IP address.public RateLimitBuilder withRejectionAction(RateLimitRejectionAction action)
action
- The action to takeIllegalArgumentException
- If the action is nullpublic static RateLimitBuilder rateLimit()
public RateLimit build()
Copyright © 2017–2021. All rights reserved.