Class FastRateLimiter

  • All Implemented Interfaces:
    RateLimiter

    public class FastRateLimiter
    extends java.lang.Object
    implements RateLimiter
    A RateLimiter that compromises accuracy for speed in order to provide maximum throughput.
    • Constructor Summary

      Constructors 
      Constructor Description
      FastRateLimiter()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void destroy()
      Cleanup no longer needed resources.
      TimeBucketCounter getBucketCounter()  
      int getDuration()  
      int getRequests()  
      int increment​(java.lang.String ipAddress)
      Increments the number of requests by the given ipAddress in the current time window.
      void setDuration​(int duration)
      Sets the configured duration value in seconds.
      void setFilterConfig​(FilterConfig filterConfig)
      Pass the FilterConfig to configure the filter.
      void setRequests​(int requests)
      Sets the configured number of requests allowed per time window.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FastRateLimiter

        public FastRateLimiter()
    • Method Detail

      • getDuration

        public int getDuration()
        Specified by:
        getDuration in interface RateLimiter
        Returns:
        the actual duration of a time window in seconds
      • setDuration

        public void setDuration​(int duration)
        Description copied from interface: RateLimiter
        Sets the configured duration value in seconds.
        Specified by:
        setDuration in interface RateLimiter
        Parameters:
        duration - The duration of the time window in seconds
      • getRequests

        public int getRequests()
        Specified by:
        getRequests in interface RateLimiter
        Returns:
        the maximum number of requests allowed per time window
      • setRequests

        public void setRequests​(int requests)
        Description copied from interface: RateLimiter
        Sets the configured number of requests allowed per time window.
        Specified by:
        setRequests in interface RateLimiter
        Parameters:
        requests - The number of requests per time window
      • increment

        public int increment​(java.lang.String ipAddress)
        Description copied from interface: RateLimiter
        Increments the number of requests by the given ipAddress in the current time window.
        Specified by:
        increment in interface RateLimiter
        Parameters:
        ipAddress - the ip address
        Returns:
        the new value after incrementing
      • destroy

        public void destroy()
        Description copied from interface: RateLimiter
        Cleanup no longer needed resources.
        Specified by:
        destroy in interface RateLimiter
      • setFilterConfig

        public void setFilterConfig​(FilterConfig filterConfig)
        Description copied from interface: RateLimiter
        Pass the FilterConfig to configure the filter.
        Specified by:
        setFilterConfig in interface RateLimiter
        Parameters:
        filterConfig - The FilterConfig used to configure the associated filter