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 Summary
Nested classes/interfaces inherited from interface io.helidon.common.concurrency.limits.LimitAlgorithm
LimitAlgorithm.Token
-
Method Summary
Modifier and TypeMethodDescriptionstatic AimdLimitConfig.Builder
builder()
Create a new fluent API builder to constructAimdLimit
instance.copy()
Create a copy of this limit with the same configuration.static AimdLimit
create()
Create a new instance with all defaults.static AimdLimit
create
(AimdLimitConfig config) Create a new instance from configuration.static AimdLimit
Create a new instance from configuration.static AimdLimit
create
(Consumer<AimdLimitConfig.Builder> consumer) Create a new instance customizing its configuration.void
Invoke a runnable within the limits of this limiter.<T> T
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.Underlying semaphore of this limit.tryAcquire
(boolean wait) Try to acquire a token, waiting for available permits for the configured amount of time, ifwait
is enabled, returning immediately otherwise.type()
Type of this implementation, to distinguish instances of same type, with differentNamedService.name()
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.helidon.common.concurrency.limits.LimitAlgorithm
tryAcquire
-
Method Details
-
builder
Create a new fluent API builder to constructAimdLimit
instance.- Returns:
- fluent API builder
-
create
Create a new instance with all defaults.- Returns:
- a new limit instance
-
create
Create a new instance from configuration.- Parameters:
config
- configuration of the AIMD limit- Returns:
- a new limit instance configured from
config
-
create
Create a new instance from configuration.- Parameters:
config
- configuration of the AIMD limit- Returns:
- a new limit instance configured from
config
-
create
Create a new instance customizing its configuration.- Parameters:
consumer
- consumer of configuration builder- Returns:
- a new limit instance configured from the builder
-
invoke
Description copied from interface:LimitAlgorithm
Invoke a callable within the limits of this limiter.Limit
implementors note: Make sure to catchIgnoreTaskException
from 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:
invoke
in interfaceLimitAlgorithm
- 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
-
invoke
Description copied from interface:LimitAlgorithm
Invoke a runnable within the limits of this limiter.Limit
implementors note: Make sure to catchIgnoreTaskException
from 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:
invoke
in interfaceLimitAlgorithm
- Parameters:
runnable
- runnable to execute within the limit- Throws:
Exception
- in case the task failed with an exception
-
tryAcquire
Description copied from interface:LimitAlgorithm
Try to acquire a token, waiting for available permits for the configured amount of time, ifwait
is enabled, returning immediately otherwise.If acquired, the caller must call one of the
LimitAlgorithm.Token
operations to release the token. If the response is empty, the limit does not have an available token.- Specified by:
tryAcquire
in interfaceLimitAlgorithm
- 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
-
semaphore
Description copied from interface:SemaphoreLimit
Underlying semaphore of this limit.- Specified by:
semaphore
in interfaceSemaphoreLimit
- Returns:
- the semaphore instance
-
name
Description copied from interface:NamedService
Name of this implementation, as provided inConfiguredProvider.create(Config, String)
.- Specified by:
name
in interfaceNamedService
- Returns:
- name of this service
-
type
Description copied from interface:NamedService
Type of this implementation, to distinguish instances of same type, with differentNamedService.name()
. Use for exampleConfiguredProvider.configKey()
to define the type.- Specified by:
type
in interfaceNamedService
- Returns:
- type of this service
-
prototype
Description copied from interface:RuntimeType.Api
The prototype as it was received when creating this runtime object instance.- Specified by:
prototype
in interfaceRuntimeType.Api<AimdLimitConfig>
- Returns:
- prototype object used to create this instance
-
copy
Description copied from interface:Limit
Create a copy of this limit with the same configuration.
-