Package org.atmosphere.interceptor
Class RateLimitingInterceptor
java.lang.Object
org.atmosphere.cpr.AtmosphereInterceptorAdapter
org.atmosphere.interceptor.RateLimitingInterceptor
- All Implemented Interfaces:
AtmosphereInterceptor,AtmosphereConfigAware,InvokationOrder
Inbound rate-limiting interceptor using a token-bucket algorithm.
Limits the number of messages a single client can send per time window,
preventing abuse and protecting server resources.
The token bucket refills at a steady rate of maxMessages / windowSeconds
tokens per second, with bursts up to maxMessages allowed. This provides
smooth rate limiting that tolerates short bursts while enforcing long-term limits.
Configuration (init-params or ApplicationConfig)
org.atmosphere.rateLimit.maxMessages— max messages per window / burst size (default: 100)org.atmosphere.rateLimit.windowSeconds— refill window in seconds (default: 60)org.atmosphere.rateLimit.policy— action when exceeded:drop(silent),disconnect(close connection) (default: drop)
Usage
framework.interceptor(new RateLimitingInterceptor());
- Since:
- 4.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumRate limit exceeded policy.Nested classes/interfaces inherited from interface org.atmosphere.interceptor.InvokationOrder
InvokationOrder.PRIORITY -
Field Summary
Fields inherited from interface org.atmosphere.interceptor.InvokationOrder
AFTER_DEFAULT, BEFORE_DEFAULT, FIRST_BEFORE_DEFAULT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconfigure(AtmosphereConfig config) Configure an AtmosphereFramework object.voiddestroy()Clean the AtmosphereInterceptor when removed or when the Atmosphere is undeployed.Invoked before anAtmosphereResourcegets dispatched toAtmosphereHandler.intpolicy()voidInvoked after anAtmosphereResourcegets dispatched toAtmosphereHandler.priority()Return the priority an AtmosphereInterceptor must be executed.toString()longlongint
-
Constructor Details
-
RateLimitingInterceptor
public RateLimitingInterceptor()
-
-
Method Details
-
configure
Description copied from interface:AtmosphereConfigAwareConfigure an AtmosphereFramework object.- Specified by:
configurein interfaceAtmosphereConfigAware- Overrides:
configurein classAtmosphereInterceptorAdapter- Parameters:
config-AtmosphereConfig
-
inspect
Description copied from interface:AtmosphereInterceptorInvoked before anAtmosphereResourcegets dispatched toAtmosphereHandler.- Specified by:
inspectin interfaceAtmosphereInterceptor- Overrides:
inspectin classAtmosphereInterceptorAdapter- Parameters:
r- aAtmosphereResource- Returns:
Action.CONTINUEorAction.SUSPENDto dispatch theAtmosphereResourceto otherAtmosphereInterceptororAtmosphereHandler. ReturnAction.TYPE.CANCELLEDto stop the processing.
-
postInspect
Description copied from interface:AtmosphereInterceptorInvoked after anAtmosphereResourcegets dispatched toAtmosphereHandler.- Specified by:
postInspectin interfaceAtmosphereInterceptor- Overrides:
postInspectin classAtmosphereInterceptorAdapter- Parameters:
r- aAtmosphereResource
-
destroy
public void destroy()Description copied from interface:AtmosphereInterceptorClean the AtmosphereInterceptor when removed or when the Atmosphere is undeployed.- Specified by:
destroyin interfaceAtmosphereInterceptor- Overrides:
destroyin classAtmosphereInterceptorAdapter
-
totalDropped
public long totalDropped()- Returns:
- total messages dropped due to rate limiting
-
totalDisconnected
public long totalDisconnected()- Returns:
- total clients disconnected due to rate limiting
-
maxMessages
public int maxMessages()- Returns:
- the configured max messages per window
-
policy
- Returns:
- the configured policy
-
trackedClients
public int trackedClients()- Returns:
- the number of currently tracked clients
-
priority
Description copied from interface:InvokationOrderReturn the priority an AtmosphereInterceptor must be executed.- Specified by:
priorityin interfaceInvokationOrder- Overrides:
priorityin classAtmosphereInterceptorAdapter- Returns:
- PRIORITY
-
toString
- Overrides:
toStringin classAtmosphereInterceptorAdapter
-