Class RateLimiter
java.lang.Object
org.deltava.beans.system.RateLimiter
A bean to track transaction volume by address and implement rate limiting.
- Since:
- 11.6
- Version:
- 11.6
- Author:
- Luke
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionRateLimiter
(boolean doMerge, int minRequests, int minTime) Initializes the hunter. -
Method Summary
Modifier and TypeMethodDescriptionaddAddress
(String addr) Adds a remote address to the hunter.void
clear()
Clears all statistics.Returns the request counters for each address.int
Returns the minimum number of request required to be categorized as a Spider.Returns the minimum time interval for Spider detection.void
load
(Collection<RequestCounter> data) Loads the limiter with data from an external source.merge()
Merges request counters based on their network blocks.void
purge()
Purges all statistics exceeding the minimum detection time.void
Clears an address' totals.void
setBlocking
(int reqs, int time) Sets whether the rate limiter should block high-volume clients.
-
Constructor Details
-
RateLimiter
public RateLimiter(boolean doMerge, int minRequests, int minTime) Initializes the hunter.- Parameters:
doMerge
- TRUE if requests should be assigned to their parent netblock, otherwise FALSEminRequests
- the minimum number of requestsminTime
- the minimum amount of time in seconds
-
-
Method Details
-
load
Loads the limiter with data from an external source.- Parameters:
data
- a Collection of RequestCounters
-
getMinRequests
public int getMinRequests()Returns the minimum number of request required to be categorized as a Spider.- Returns:
- the number of requests
-
getMinTime
Returns the minimum time interval for Spider detection.- Returns:
- the interval as a Duration
-
getCounters
Returns the request counters for each address.- Returns:
- the request counters
-
setBlocking
public void setBlocking(int reqs, int time) Sets whether the rate limiter should block high-volume clients.- Parameters:
reqs
- the number of requeststime
- the block time in seconds
-
remove
-
get
-
addAddress
Adds a remote address to the hunter.- Parameters:
addr
- the remote address- Returns:
- a Result
-
clear
public void clear()Clears all statistics. -
merge
Merges request counters based on their network blocks.- Returns:
- the merged counters
-
purge
public void purge()Purges all statistics exceeding the minimum detection time.
-