Package net.guizhanss.guizhanlib.common
Class RateLimit<K>
java.lang.Object
net.guizhanss.guizhanlib.common.RateLimit<K>
- Type Parameters:
K- The type of key.
This package provides rate limit feature.
- Author:
- ybw0014
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanIncreases the times of visits by 1.booleanIncreases the times of visits.intgetLimit()Get the overall limit of visits.intgetRemaining(K key) Get remaining times of visitsintGet the used visits.voidReset rate limit
-
Constructor Details
-
RateLimit
public RateLimit(long time, int visits) Constructor.- Parameters:
time- Time period in milliseconds.visits- The limit times of visits.
-
-
Method Details
-
getLimit
public int getLimit()Get the overall limit of visits.- Returns:
- The overall limit of visits.
-
getUsed
Get the used visits.- Parameters:
key- The query key.- Returns:
- Used times of visits.
-
getRemaining
Get remaining times of visits- Parameters:
key- The query key.- Returns:
- Remaining times of visits
-
add
Increases the times of visits.- Parameters:
key- The query key.visits- The times of visits- Returns:
- Whether the action succeeds.
-
add
Increases the times of visits by 1.- Parameters:
key- The query key.- Returns:
- Whether the action succeeds.
-
reset
Reset rate limit- Parameters:
key- The query key.
-