Class SharedParamManager
java.lang.Object
org.apache.synapse.commons.throttle.core.SharedParamManager
-
Method Summary
Modifier and TypeMethodDescriptionstatic longaddAndGetDistributedCounter(String id, long value) Add given value to the distribute counter of caller context of given id.static longasyncGetAndAddDistributedCounter(String id, long value) Asynchronously add given value to the distribute counter of caller context of given id.static longasyncGetAndAlterDistributedCounter(String id, long value) Asynchronously add given value to the distribute counter of caller context of given id.static longReturn distributed shared counter for this caller context with given id.static longReturn hazelcast shared timestamp for this caller context with given id.static longGet the time-to-live value for the given keystatic long[]getWindowState(String id) Atomically reads the window timestamp and counter for the given caller id.static longincrWindowCounter(String id, long delta, long expiryTime) Atomically increments the window counter bydelta.static booleanlockSharedKeys(String callerContextId, String lockValue) Acquire lock for the given callerContext (with the given value), so that another process cannot acquire the same lockstatic voidreleaseSharedKeys(String callerContextId) Release the lock of the given callerContextstatic voidReleases the per-caller window lock acquired bytryWindowLock(java.lang.String, long).static voidremoveCounter(String id) Destroy hazelcast global counter, if it's local then remove the map entrystatic voidDestroy hazelcast shared timggestamp counter, if it's local then remove the map entrystatic voidsetDistributedCounter(String id, long value) Set distribute counter of caller context of given id to the provided value.static voidsetDistributedCounterWithExpiry(String id, long value, long expiryTime) Set the distributed counter with the given id key with an expiry timestatic voidsetExpiryTime(String id, long expiryTimeStamp) static voidsetSharedTimestamp(String id, long timestamp) Set distribute timestamp of caller context of given id to the provided value.static voidsetSharedTimestampWithExpiry(String id, long timestamp, long expiryTime) Set the shared timestamp with the given id key with an expiry timestatic voidUnconditionally sets a throttle window by overwriting both timestamp and counter, then refreshing the TTL.static booleantryWindowLock(String id, long expiryTime) Tries to acquire the per-caller window lock without blocking.
-
Method Details
-
getDistributedCounter
Return distributed shared counter for this caller context with given id. If it's not distributed will get from the local counter- Parameters:
id- of the shared counter- Returns:
- shared hazelcast current shared counter
-
setDistributedCounter
Set distribute counter of caller context of given id to the provided value. If it's not distributed do the same for local counter- Parameters:
id- of the caller contextvalue- to set to the global counter
-
setDistributedCounterWithExpiry
Set the distributed counter with the given id key with an expiry time- Parameters:
id- key idvalue- value to setexpiryTime- expiry time in milliseconds
-
addAndGetDistributedCounter
Add given value to the distribute counter of caller context of given id. If it's not distributed return local counter- Parameters:
id- of the caller contextvalue- to set to the global counter
-
asyncGetAndAddDistributedCounter
Asynchronously add given value to the distribute counter of caller context of given id. If it's not distributed return local counter. This will return global value before add the provided counter- Parameters:
id- of the caller contextvalue- to set to the global counter
-
asyncGetAndAlterDistributedCounter
Asynchronously add given value to the distribute counter of caller context of given id. If it's not distributed return local counter. This will return global value before add the provided counter- Parameters:
id- of the caller contextvalue- to set to the global counter
-
removeCounter
Destroy hazelcast global counter, if it's local then remove the map entry- Parameters:
id- of the caller context
-
removeTimestamp
Destroy hazelcast shared timggestamp counter, if it's local then remove the map entry- Parameters:
id- of the caller context
-
setExpiryTime
-
getTtl
Get the time-to-live value for the given key- Parameters:
key- name key of the key- Returns:
- time-to-live value
-
getWindowState
Atomically reads the window timestamp and counter for the given caller id.- Parameters:
id- caller context id- Returns:
- long[2]: {timestamp, counter}
-
setWindow
Unconditionally sets a throttle window by overwriting both timestamp and counter, then refreshing the TTL. Must be called while holding the per-caller window lock.- Parameters:
id- caller context idcount- initial counter valuets- window first-access time in millisecondsexpiryTime- absolute expiry timestamp in milliseconds (ts + unitTime)
-
incrWindowCounter
Atomically increments the window counter bydelta.- Parameters:
id- caller context iddelta- value to add to the counter- Returns:
- new global counter value after the increment
-
tryWindowLock
Tries to acquire the per-caller window lock without blocking. Returnstrueif the lock was acquired,falseif another node holds it. The lock TTL is set toexpiryTime(absolute window boundary) so it auto-expires when the window ends, even if the holder crashes mid-tick.- Parameters:
id- caller context idexpiryTime- absolute window-end timestamp in ms (localFAT + unitTime)- Returns:
- true if this node acquired the lock
-
releaseWindowLock
Releases the per-caller window lock acquired bytryWindowLock(java.lang.String, long). Should be called in afinallyblock after lock-protected Redis work completes.- Parameters:
id- caller context id
-