Package org.atmosphere.interceptor
Class BackpressureInterceptor
java.lang.Object
org.atmosphere.cpr.AtmosphereInterceptorAdapter
org.atmosphere.interceptor.BackpressureInterceptor
- All Implemented Interfaces:
AtmosphereInterceptor,AtmosphereConfigAware,InvokationOrder
Backpressure interceptor that tracks per-client pending message counts and applies
a configurable policy (drop-oldest, drop-newest, or disconnect) when a client
exceeds the high water mark.
- Since:
- 4.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumBackpressure drop 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 TypeMethodDescriptionbooleanallowMessage(String uuid) Check if a message can be delivered to the given resource.voidconfigure(int highWaterMark, BackpressureInterceptor.Policy policy) Programmatically configure the high water mark and drop policy.voidconfigure(AtmosphereConfig config) Configure an AtmosphereFramework object.intInvoked before anAtmosphereResourcegets dispatched toAtmosphereHandler.voidmessageDelivered(String uuid) Signal that a previously counted pending message has left the write queue (delivered to the client or evicted by a drop policy).intpendingCount(String uuid) policy()policyFromString(String policyStr) Parse a policy string (case-insensitive) into aBackpressureInterceptor.Policy.toString()longlongMethods inherited from class org.atmosphere.cpr.AtmosphereInterceptorAdapter
destroy, postInspect, priority
-
Constructor Details
-
BackpressureInterceptor
public BackpressureInterceptor()
-
-
Method Details
-
configure
Description copied from interface:AtmosphereConfigAwareConfigure an AtmosphereFramework object.- Specified by:
configurein interfaceAtmosphereConfigAware- Overrides:
configurein classAtmosphereInterceptorAdapter- Parameters:
config-AtmosphereConfig
-
configure
Programmatically configure the high water mark and drop policy. Used by consumers (such as theDefaultBroadcasterwrite path) that resolve the policy from their own configuration rather than from interceptor init parameters.- Parameters:
highWaterMark- the per-client pending high water mark (values < 1 are clamped to 1)policy- the drop policy to apply once the high water mark is exceeded
-
policyFromString
Parse a policy string (case-insensitive) into aBackpressureInterceptor.Policy. Unknown values fall back toBackpressureInterceptor.Policy.DROP_OLDEST.- Parameters:
policyStr- the policy string, e.g.drop-oldest,drop-newest,disconnect- Returns:
- the resolved policy
-
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.
-
allowMessage
Check if a message can be delivered to the given resource. Call this before queueing a message for delivery.- Parameters:
uuid- the resource UUID- Returns:
- true if the message should be delivered, false if dropped
-
messageDelivered
Signal that a previously counted pending message has left the write queue (delivered to the client or evicted by a drop policy). Decrements the per-client pending count, never below zero. Consumers wiringallowMessage(String)into a real write/queue path MUST call this once per message removed from the queue, otherwise the pending count leaks upward and every message is eventually treated as over-limit.- Parameters:
uuid- the resource UUID
-
pendingCount
- Returns:
- the number of pending messages for the given resource
-
totalDrops
public long totalDrops()- Returns:
- total messages dropped due to backpressure
-
totalDisconnects
public long totalDisconnects()- Returns:
- total clients disconnected due to backpressure
-
highWaterMark
public int highWaterMark()- Returns:
- the configured high water mark
-
policy
- Returns:
- the configured policy
-
toString
- Overrides:
toStringin classAtmosphereInterceptorAdapter
-