# Class RateLimiterBase

java.lang.Object
org.apache.catalina.util.RateLimiterBase

All Implemented Interfaces:
  `RateLimiter`

Direct Known Subclasses:
  `ExactRateLimiter`, `FastRateLimiter`

public abstract class RateLimiterBase extends Object implements RateLimiter
Base implementation of `RateLimiter`, provides runtime data maintenance mechanism monitor.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `RateLimiterBase()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `destroy()`
  Cleanup no longer needed resources.
  `TimeBucketCounterBase`
  `getBucketCounter()`
  Returns the internal instance of `TimeBucketCounterBase`.
  `protected abstract String`
  `getDefaultPolicyName()`
  If policy name has not been specified, the first call of `getPolicyName()` returns an auto-generated policy name using the default policy name as prefix and followed by auto-increase index.
  `int`
  `getDuration()`
  `String`
  `getPolicyName()`
  `int`
  `getRequests()`
  `int`
  `increment(String identifier)`
  Increments the number of requests by the given identifier in the current time window.
  `protected abstract TimeBucketCounterBase`
  `newCounterInstance(int duration, ScheduledExecutorService utilityExecutor)`
  Instantiate an instance of `TimeBucketCounterBase` for specific time bucket size.
  `void`
  `setDuration(int duration)`
  Sets the configured duration value in seconds.
  `void`
  `setFilterConfig(FilterConfig filterConfig)`
  Pass the FilterConfig to configure the filter.
  `void`
  `setPolicyName(String name)`
  Sets the policy name, otherwise an auto-generated name is used.
  `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`

  ### Methods inherited from interface org.apache.catalina.util.RateLimiter

  `getPolicy, getQuota`

- ## Constructor Details

  - ### RateLimiterBase

    public RateLimiterBase()

- ## Method Details

  - ### getDefaultPolicyName

    protected abstract String getDefaultPolicyName()
    If policy name has not been specified, the first call of `getPolicyName()` returns an auto-generated policy name using the default policy name as prefix and followed by auto-increase index.
    Returns:
      default policy name, as a prefix of auto-generated policy name.

  - ### getPolicyName

    public String getPolicyName()
    Specified by:
      `getPolicyName` in interface `RateLimiter`
    Returns:
      name of RateLimit policy

  - ### setPolicyName

    public void setPolicyName(String name)
    Description copied from interface: `RateLimiter`
    Sets the policy name, otherwise an auto-generated name is used.
    Specified by:
      `setPolicyName` in interface `RateLimiter`
    Parameters:
      `name` - of rate limit policy

  - ### 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(String identifier)
    Description copied from interface: `RateLimiter`
    Increments the number of requests by the given identifier in the current time window.
    Specified by:
      `increment` in interface `RateLimiter`
    Parameters:
      `identifier` - the identifier for which the number of associated requests should be incremented
    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`

  - ### newCounterInstance

    protected abstract TimeBucketCounterBase newCounterInstance(int duration, ScheduledExecutorService utilityExecutor)
    Instantiate an instance of `TimeBucketCounterBase` for specific time bucket size. Concrete classes determine its counter policy by returning different implementation instances.
    Parameters:
      `duration` - size of each time bucket in seconds
      `utilityExecutor` - the executor
    Returns:
      counter instance of `TimeBucketCounterBase`

  - ### 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

  - ### getBucketCounter

    public TimeBucketCounterBase getBucketCounter()
    Returns the internal instance of `TimeBucketCounterBase`.
    Returns:
      instance of `TimeBucketCounterBase`