Class BucketLimiter

java.lang.Object
it.univr.passportease.helper.ratelimiter.BucketLimiter

@Service public class BucketLimiter extends Object
This class is used to resolve the bucket for each method. It uses a ConcurrentHashMap to store the buckets. The algorithm used is called "Token Bucket". It goes as follows:
  • Each bucket has a capacity and a refill rate.
  • When a request arrives, the bucket is checked to see if it has enough tokens to satisfy the request.
  • If it does, the request is served and the bucket is updated.
  • If it doesn't, the request is rejected.
  • Each bucket has a refill rate, which is the rate at which the bucket is refilled with tokens.
  • Each bucket has a capacity, which is the maximum number of tokens it can hold.
  • Field Details

    • bucketCache

      private final Map<String,io.github.bucket4j.Bucket> bucketCache
      The cache of the buckets.
  • Constructor Details

    • BucketLimiter

      public BucketLimiter()
  • Method Details

    • resolveBucket

      public io.github.bucket4j.Bucket resolveBucket(RateLimiter methodName)
      This method is used to resolve the bucket for each method. It uses a ConcurrentHashMap to store the buckets.
      Parameters:
      methodName - The name of the method to resolve the bucket for.
      Returns:
      The bucket for the given method.