Package com.github.gpluscb.ggjava.api
Interface RateLimiter
- 
 public interface RateLimiterUsed for scheduling tasks according to rate limits.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Interface Description static classRateLimiter.BucketBuilderUsed for building instances of RateLimiter that respect a bucket system.static classRateLimiter.SimpleBuilderUsed for building instances of RateLimiter that respect a minimal spacing between tasks.
 - 
Method SummaryAll Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static RateLimiter.BucketBuilderbucketBuilder()For creating instances of RateLimiter that will respect a bucket system.voidenqueue(java.util.function.IntFunction<java.util.concurrent.CompletableFuture<java.lang.Boolean>> task)Enqueues an asynchronous task to be executed according to the rate limit this instance represents.booleanisShutDown()Whether the instance is already shut downjava.util.concurrent.CompletableFuture<java.lang.Void>shutdown()Shuts down the instance gracefully.static RateLimiter.SimpleBuildersimpleBuilder()For creating instances of RateLimiter that will respect a simple system where tasks are spaced by a certain limit.
 
- 
- 
- 
Method Detail- 
enqueuevoid enqueue(@Nonnull java.util.function.IntFunction<java.util.concurrent.CompletableFuture<java.lang.Boolean>> task)Enqueues an asynchronous task to be executed according to the rate limit this instance represents. The int applied to the function is the number of retries this task is on in this iteration. If this is the first time this task is executed it will be 0, it will be 1 on the first retry and so on. Complete theCompletableFutureyou return with true in the function if you want to retry this task.- Parameters:
- task- the task to enqueue
- Throws:
- java.lang.IllegalArgumentException- task is null
- java.lang.IllegalStateException- if the instance is already shut down
 
 - 
shutdown@Nonnull java.util.concurrent.CompletableFuture<java.lang.Void> shutdown() Shuts down the instance gracefully. Already enqueued tasks will still be executed.- Returns:
- a CompletableFuture that will be completed once the shutdown is completed
 
 - 
isShutDownboolean isShutDown() Whether the instance is already shut down- Returns:
- true if the instance is shut down
 
 - 
simpleBuilder@Nonnull static RateLimiter.SimpleBuilder simpleBuilder() For creating instances of RateLimiter that will respect a simple system where tasks are spaced by a certain limit.- Returns:
- a new SimpleBuilder for building a RateLimiter
 
 - 
bucketBuilder@Nonnull static RateLimiter.BucketBuilder bucketBuilder() For creating instances of RateLimiter that will respect a bucket system.- Returns:
- a new BucketBuilder for building a RateLimter
 
 
- 
 
-