Class AbstractRateLimiter<T>
java.lang.Object
ai.redouble.nucleo.harness.admission.AbstractRateLimiter<T>
- Type Parameters:
T- the amount type
- All Implemented Interfaces:
LimiterIdentity, RateLimiter<T>
- Direct Known Subclasses:
CountingGate, ElasticWindowRateLimiter, MemoryPressureGate, TokenBucketRateLimiter
public abstract class AbstractRateLimiter<T>
extends Object
implements RateLimiter<T>, LimiterIdentity
Base class for accounts that are their own identity: the wake slot
Admission
installs, the RateLimiter.Replenishment.RELEASE default that fits every capacity gate built
directly on this class, and the nominal (null) status indicator.
Emission and waiter counting are not here. Admission owns the wait, so it owns
the LimiterEvents that describe it; an account only
reports its identity and moves its counters.
The two time-based families override replenishment():
ElasticWindowRateLimiter, whose override is final so none of its per-service
subclasses can drift, and TokenBucketRateLimiter. A new limiter whose permits return
with the clock rather than with the work must override too.
- Since:
- 0.1 (2026-04-14)
- Author:
- Andrey Santrosyan
-
Nested Class Summary
Nested classes/interfaces inherited from interface RateLimiter
RateLimiter.Replenishment -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaccountFor(T amount) The identity the given amount debits: this limiter for a plain account, the routed bucket for a router.protected final voidRuns the installed wake, if any.voidonCapacityChange(Runnable wake) Installs the single wake this account runs after any self-change that can only increase capacity: a throttle relaxation, a cap raised from headers, a circuit closing, a pushed fleet allotment.Defaults toRateLimiter.Replenishment.RELEASE, which is what a permit means for the capacity gates built directly on this class - a semaphore slot, a pooled connection, heap headroom.Short human-readable tag describing an abnormal operational state of this account:"blocked","probing","throttle:2.0x","pace:1500ms".Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface LimiterIdentity
capacity, currentInUse, getStatus, limiterCategory, limiterNameMethods inherited from interface RateLimiter
earliestFit, fits, give, observeHeld, onRateLimitError, onRateLimitError, onSuccess, onSuccess, requiresHttpConnection, tryTake
-
Constructor Details
-
AbstractRateLimiter
public AbstractRateLimiter()
-
-
Method Details
-
onCapacityChange
Description copied from interface:RateLimiterInstalls the single wake this account runs after any self-change that can only increase capacity: a throttle relaxation, a cap raised from headers, a circuit closing, a pushed fleet allotment. The wake is a bare unpark of the admission evaluator and never re-enters an account or the monitor, so it may be run from anywhere, under any lock.nullclears the slot. Decreases never wake anyone.- Specified by:
onCapacityChangein interfaceRateLimiter<T>
-
capacityChanged
protected final void capacityChanged()Runs the installed wake, if any. Subclasses call this after a self-change that can only increase capacity. The wake is a bare unpark and safe to run under any lock. -
accountFor
Description copied from interface:RateLimiterThe identity the given amount debits: this limiter for a plain account, the routed bucket for a router. Head reservation, waiter counts and events all key on it.- Specified by:
accountForin interfaceRateLimiter<T>
-
replenishment
Defaults toRateLimiter.Replenishment.RELEASE, which is what a permit means for the capacity gates built directly on this class - a semaphore slot, a pooled connection, heap headroom. All of those are genuinely free again when the work ends.- Specified by:
replenishmentin interfaceRateLimiter<T>
-
statusIndicator
Description copied from interface:LimiterIdentityShort human-readable tag describing an abnormal operational state of this account:"blocked","probing","throttle:2.0x","pace:1500ms". Returnsnullwhen the account is in its nominal state. Consumers surface it alongside capacity and in-use so an out-of-sorts account is visible even when its numeric columns look calm.- Specified by:
statusIndicatorin interfaceLimiterIdentity
-