Class RateLimiterBase
java.lang.Object
org.apache.catalina.util.RateLimiterBase
- All Implemented Interfaces:
RateLimiter
- Direct Known Subclasses:
ExactRateLimiter, FastRateLimiter
Base implementation of
RateLimiter, provides runtime data maintenance mechanism monitor.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()Cleanup no longer needed resources.Returns the internal instance ofTimeBucketCounterBase.protected abstract StringIf policy name has not been specified, the first call ofgetPolicyName()returns an auto-generated policy name using the default policy name as prefix and followed by auto-increase index.intintintIncrements the number of requests by the given identifier in the current time window.protected abstract TimeBucketCounterBasenewCounterInstance(int duration, ScheduledExecutorService utilityExecutor) Instantiate an instance ofTimeBucketCounterBasefor specific time bucket size.voidsetDuration(int duration) Sets the configured duration value in seconds.voidsetFilterConfig(FilterConfig filterConfig) Pass the FilterConfig to configure the filter.voidsetPolicyName(String name) Sets the policy name, otherwise an auto-generated name is used.voidsetRequests(int requests) Sets the configured number of requests allowed per time window.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface RateLimiter
getPolicy, getQuota
-
Constructor Details
-
RateLimiterBase
public RateLimiterBase()
-
-
Method Details
-
getDefaultPolicyName
If policy name has not been specified, the first call ofgetPolicyName()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
- Specified by:
getPolicyNamein interfaceRateLimiter- Returns:
- name of RateLimit policy
-
setPolicyName
Description copied from interface:RateLimiterSets the policy name, otherwise an auto-generated name is used.- Specified by:
setPolicyNamein interfaceRateLimiter- Parameters:
name- of rate limit policy
-
getDuration
public int getDuration()- Specified by:
getDurationin interfaceRateLimiter- Returns:
- the actual duration of a time window in seconds
-
setDuration
public void setDuration(int duration) Description copied from interface:RateLimiterSets the configured duration value in seconds.- Specified by:
setDurationin interfaceRateLimiter- Parameters:
duration- The duration of the time window in seconds
-
getRequests
public int getRequests()- Specified by:
getRequestsin interfaceRateLimiter- Returns:
- the maximum number of requests allowed per time window
-
setRequests
public void setRequests(int requests) Description copied from interface:RateLimiterSets the configured number of requests allowed per time window.- Specified by:
setRequestsin interfaceRateLimiter- Parameters:
requests- The number of requests per time window
-
increment
Description copied from interface:RateLimiterIncrements the number of requests by the given identifier in the current time window.- Specified by:
incrementin interfaceRateLimiter- 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:RateLimiterCleanup no longer needed resources.- Specified by:
destroyin interfaceRateLimiter
-
newCounterInstance
protected abstract TimeBucketCounterBase newCounterInstance(int duration, ScheduledExecutorService utilityExecutor) Instantiate an instance ofTimeBucketCounterBasefor specific time bucket size. Concrete classes determine its counter policy by returning different implementation instances.- Parameters:
duration- size of each time bucket in secondsutilityExecutor- the executor- Returns:
- counter instance of
TimeBucketCounterBase
-
setFilterConfig
Description copied from interface:RateLimiterPass the FilterConfig to configure the filter.- Specified by:
setFilterConfigin interfaceRateLimiter- Parameters:
filterConfig- The FilterConfig used to configure the associated filter
-
getBucketCounter
Returns the internal instance ofTimeBucketCounterBase.- Returns:
- instance of
TimeBucketCounterBase
-