Package com.networknt.limit
Class RateLimiter
- java.lang.Object
-
- com.networknt.limit.RateLimiter
-
public class RateLimiter extends Object
Rate limit logic for light-4j framework. The config will define in the limit.yml config file. By default Rate limit will handle on the server(service) level. But framework support client and address level limitation- Author:
- Gavin Chen
-
-
Field Summary
Fields Modifier and Type Field Description protected LimitConfigconfig
-
Constructor Summary
Constructors Constructor Description RateLimiter(LimitConfig config)Load config and initial model by Rate limit key.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RateLimitResponsehandleRequest(io.undertow.server.HttpServerExchange exchange, LimitKey limitKey)RateLimitResponseisAllowByServer(String path)Handle logic for Server type (key = server) rate limitprotected RateLimitResponseisAllowDirect(String directKey, String path, String type)Handle logic for direct rate limit setting for address, client and user.
-
-
-
Field Detail
-
config
protected LimitConfig config
-
-
Constructor Detail
-
RateLimiter
public RateLimiter(LimitConfig config) throws Exception
Load config and initial model by Rate limit key.- Parameters:
config- LimitConfig object- Throws:
Exception- runtime exception
-
-
Method Detail
-
handleRequest
public RateLimitResponse handleRequest(io.undertow.server.HttpServerExchange exchange, LimitKey limitKey)
-
isAllowDirect
protected RateLimitResponse isAllowDirect(String directKey, String path, String type)
Handle logic for direct rate limit setting for address, client and user. Use the type for differential the address/client/user- Parameters:
directKey- direct keypath- Stringtype- String- Returns:
- RateLimitResponse response
-
isAllowByServer
public RateLimitResponse isAllowByServer(String path)
Handle logic for Server type (key = server) rate limit- Parameters:
path- String- Returns:
- RateLimitResponse rate limit response
-
-