Class AimdLimit
- All Implemented Interfaces:
- RuntimeType.Api<AimdLimitConfig>,- Limit,- LimitAlgorithm,- SemaphoreLimit,- NamedService
The additive-increase/multiplicative-decrease (AIMD) algorithm is a feedback control algorithm best known for its use in TCP congestion control. AIMD combines linear growth of the congestion window when there is no congestion with an exponential reduction when congestion is detected.
- 
Nested Class SummaryNested classes/interfaces inherited from interface io.helidon.common.concurrency.limits.LimitAlgorithmLimitAlgorithm.Outcome, LimitAlgorithm.Result<T>, LimitAlgorithm.Token
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intDefault length of the queue.static final StringTimeout of a request that is enqueued.
- 
Method SummaryModifier and TypeMethodDescriptionstatic AimdLimitConfig.Builderbuilder()Create a new fluent API builder to constructAimdLimitinstance.<T> LimitAlgorithm.Result<T> Invoke a callable within the limits of this limiter, invoking the providedConsumerwith theLimitAlgorithm.Outcomeresulting from applying the limit algorithm.copy()Create a copy of this limit with the same configuration.static AimdLimitcreate()Create a new instance with all defaults.static AimdLimitcreate(AimdLimitConfig config) Create a new instance from configuration.static AimdLimitCreate a new instance from configuration.static AimdLimitcreate(Consumer<AimdLimitConfig.Builder> consumer) Create a new instance customizing its configuration.voidInitialization method for this limit.voidDeprecated, for removal: This API element is subject to removal in a future version.Invoke a runnable within the limits of this limiter.<T> TDeprecated, for removal: This API element is subject to removal in a future version.Invoke a callable within the limits of this limiter.name()Name of this implementation, as provided inConfiguredProvider.create(Config, String).The prototype as it was received when creating this runtime object instance.Invoke a runnable within the limits of this limiter, invoking the providedConsumerwith theLimitAlgorithm.Outcomeresulting from applying the limit algorithm.Underlying semaphore of this limit.Deprecated, for removal: This API element is subject to removal in a future version.Try to acquire a token, waiting for available permits for the configured amount of time, if queuing is enabled.tryAcquire(boolean wait) Deprecated, for removal: This API element is subject to removal in a future version.Try to acquire a token, waiting for available permits for the configured amount of time, ifwaitis enabled, returning immediately otherwise.tryAcquireOutcome(boolean wait) Tries to acquire a token, waiting for available permits for the configured amount of time, ifwaitis enabled, returning immediately otherwise.type()Type of this implementation, to distinguish instances of same type, with differentNamedService.name().Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.helidon.common.concurrency.limits.LimitAlgorithminvoke, invoke, tryAcquire, tryAcquire, tryAcquireOutcome
- 
Field Details- 
DEFAULT_QUEUE_LENGTHpublic static final int DEFAULT_QUEUE_LENGTHDefault length of the queue.- See Also:
 
- 
DEFAULT_QUEUE_TIMEOUT_DURATIONTimeout of a request that is enqueued.- See Also:
 
 
- 
- 
Method Details- 
builderCreate a new fluent API builder to constructAimdLimitinstance.- Returns:
- fluent API builder
 
- 
createCreate a new instance with all defaults.- Returns:
- a new limit instance
 
- 
createCreate a new instance from configuration.- Parameters:
- config- configuration of the AIMD limit
- Returns:
- a new limit instance configured from config
 
- 
createCreate a new instance from configuration.- Parameters:
- config- configuration of the AIMD limit
- Returns:
- a new limit instance configured from config
 
- 
createCreate a new instance customizing its configuration.- Parameters:
- consumer- consumer of configuration builder
- Returns:
- a new limit instance configured from the builder
 
- 
callDescription copied from interface:LimitAlgorithmInvoke a callable within the limits of this limiter, invoking the providedConsumerwith theLimitAlgorithm.Outcomeresulting from applying the limit algorithm.Note that custom implementations of this interface might not implement this method, in which case the caller's limit outcome consumer receives an "unknown" outcome. Clearly the algorithm made a decision, but does not expose it to callers. Limitimplementor's notes:- Make sure to catch IgnoreTaskExceptionfrom the callable, and call itsIgnoreTaskException.handle()to either return the provided result, or throw the exception after ignoring the timing for future decisions.
- Make sure the limitOutcomeConsumeris non-null, and after determining the disposition of the item of work create a suitableLimitOutcomeand pass it to the consumer. Also, make sure to use an outcome-aware token internally so when the caller invokes the token's methods the outcome is updated accordingly.
 - Specified by:
- callin interface- LimitAlgorithm
- Type Parameters:
- T- the callable return type
- Parameters:
- callable- callable to execute within the limit
- Returns:
- result of the callable with the outcome
- Throws:
- Exception- in case the task failed with an exception
 
- Make sure to catch 
- 
runDescription copied from interface:LimitAlgorithmInvoke a runnable within the limits of this limiter, invoking the providedConsumerwith theLimitAlgorithm.Outcomeresulting from applying the limit algorithm.Note that custom implementations of this interface might not implement this method, in which case the caller's limit outcome consumer receives an "unknown" outcome. Clearly the algorithm made a decision, but does not expose it to callers. Limitimplementor's notes:- Make sure to catch IgnoreTaskExceptionfrom the runnable, and call itsIgnoreTaskException.handle()to either return the provided result, or throw the exception after ignoring the timing for future decisions.
- Make sure the limitOutcomeConsumeris non-null, and after determining the disposition of the item of work create a suitableLimitOutcomeand pass it to the consumer. Also, make sure to use an outcome-aware token internally so when the caller invokes the token's methods the outcome is updated accordingly.
 - Specified by:
- runin interface- LimitAlgorithm
- Parameters:
- runnable- runnable to execute within the limit
- Returns:
- Outcomefrom the limit algorithm
- Throws:
- Exception- in case the task failed with an exception
 
- Make sure to catch 
- 
tryAcquireOutcomeDescription copied from interface:LimitAlgorithmTries to acquire a token, waiting for available permits for the configured amount of time, ifwaitis enabled, returning immediately otherwise. Concrete implementations should invoke the providedoutcomeConsumer.Note that custom implementations of this interface might not implement this method, in which case the caller's limit outcome consumer receives an "unknown" outcome. Clearly the algorithm made a decision, but does not expose it to callers. If acquired, the caller must call one of the LimitAlgorithm.Tokenoperations to release the token. If the response is empty, the limit does not have an available token.- Specified by:
- tryAcquireOutcomein interface- LimitAlgorithm
- Parameters:
- wait- whether to wait in the queue (if one is configured/available in the limit), or to return immediately
- Returns:
- acquired token, or empty if there is no available token
 
- 
semaphoreDescription copied from interface:SemaphoreLimitUnderlying semaphore of this limit.- Specified by:
- semaphorein interface- SemaphoreLimit
- Returns:
- the semaphore instance
 
- 
nameDescription copied from interface:NamedServiceName of this implementation, as provided inConfiguredProvider.create(Config, String).- Specified by:
- namein interface- NamedService
- Returns:
- name of this service
 
- 
typeDescription copied from interface:NamedServiceType of this implementation, to distinguish instances of same type, with differentNamedService.name(). Use for exampleConfiguredProvider.configKey()to define the type.- Specified by:
- typein interface- NamedService
- Returns:
- type of this service
 
- 
prototypeDescription copied from interface:RuntimeType.ApiThe prototype as it was received when creating this runtime object instance.- Specified by:
- prototypein interface- RuntimeType.Api<AimdLimitConfig>
- Returns:
- prototype object used to create this instance
 
- 
copyDescription copied from interface:LimitCreate a copy of this limit with the same configuration.
- 
initDescription copied from interface:LimitInitialization method for this limit. This method can be used for any task, including metrics initialization.
- 
invokeDeprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:LimitAlgorithmInvoke a callable within the limits of this limiter.Limitimplementor's note: Make sure to catchIgnoreTaskExceptionfrom the callable, and call itsIgnoreTaskException.handle()to either return the provided result, or throw the exception after ignoring the timing for future decisions.- Specified by:
- invokein interface- LimitAlgorithm
- Type Parameters:
- T- the callable return type
- Parameters:
- callable- callable to execute within the limit
- Returns:
- result of the callable
- Throws:
- Exception- in case the task failed with an exception
 
- 
invokeDeprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:LimitAlgorithmInvoke a runnable within the limits of this limiter.Limitimplementor's note: Make sure to catchIgnoreTaskExceptionfrom the runnable, and call itsIgnoreTaskException.handle()to either return the provided result, or throw the exception after ignoring the timing for future decisions.- Specified by:
- invokein interface- LimitAlgorithm
- Parameters:
- runnable- runnable to execute within the limit
- Throws:
- Exception- in case the task failed with an exception
 
- 
tryAcquireDeprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:LimitAlgorithmTry to acquire a token, waiting for available permits for the configured amount of time, if queuing is enabled.If acquired, the caller must call one of the LimitAlgorithm.Tokenoperations to release the token. If the response is empty, the limit does not have an available token.- Specified by:
- tryAcquirein interface- LimitAlgorithm
- Returns:
- acquired token, or empty if there is no available token
 
- 
tryAcquireDeprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:LimitAlgorithmTry to acquire a token, waiting for available permits for the configured amount of time, ifwaitis enabled, returning immediately otherwise.If acquired, the caller must call one of the LimitAlgorithm.Tokenoperations to release the token. If the response is empty, the limit does not have an available token.- Specified by:
- tryAcquirein interface- LimitAlgorithm
- Parameters:
- wait- whether to wait in the queue (if one is configured/available in the limit), or to return immediately
- Returns:
- acquired token, or empty if there is no available token
 
 
-