Package org.javacord.api.util.ratelimit
Class LocalRatelimiter
- java.lang.Object
-
- org.javacord.api.util.ratelimit.LocalRatelimiter
-
- All Implemented Interfaces:
Ratelimiter
public class LocalRatelimiter extends Object implements Ratelimiter
An implementation ofRatelimiterthat allows simple local ratelimits.
-
-
Constructor Summary
Constructors Constructor Description LocalRatelimiter(int amount, int seconds)Creates a new local ratelimiter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetAmount()Gets the amount available per reset interval.longgetNextResetNanos()Gets the next time the quota resets.intgetRemainingQuota()Gets the remaining quota in the current reset interval.intgetSeconds()Gets the time to wait until the available quota resets in seconds.voidrequestQuota()Blocks the requesting thread until a quota becomes available.
-
-
-
Method Detail
-
getAmount
public int getAmount()
Gets the amount available per reset interval.- Returns:
- The amount.
-
getSeconds
public int getSeconds()
Gets the time to wait until the available quota resets in seconds.- Returns:
- The time to wait until the available quota resets.
-
getNextResetNanos
public long getNextResetNanos()
Gets the next time the quota resets.Use
System.nanoTime()to calculate the absolute difference.- Returns:
- The next time the quota resets. Can be in the past.
-
getRemainingQuota
public int getRemainingQuota()
Gets the remaining quota in the current reset interval.- Returns:
- The remaining quota.
-
requestQuota
public void requestQuota() throws InterruptedExceptionDescription copied from interface:RatelimiterBlocks the requesting thread until a quota becomes available.- Specified by:
requestQuotain interfaceRatelimiter- Throws:
InterruptedException- if any thread has interrupted the current thread. The interrupted status of the current thread is cleared when this exception is thrown.
-
-