Class FixedLimit
java.lang.Object
io.helidon.common.concurrency.limits.FixedLimit
- All Implemented Interfaces:
RuntimeType.Api<FixedLimitConfig>,Limit,LimitAlgorithm,SemaphoreLimit,NamedService
public class FixedLimit
extends Object
implements Limit, SemaphoreLimit, RuntimeType.Api<FixedLimitConfig>
Semaphore based limit, that supports queuing for a permit, and timeout on the queue.
The default behavior is non-queuing.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.helidon.common.concurrency.limits.LimitAlgorithm
LimitAlgorithm.Token -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault limit, meaning unlimited execution.static final intDefault length of the queue.static final StringTimeout of a request that is enqueued. -
Method Summary
Modifier and TypeMethodDescriptionstatic FixedLimitConfig.Builderbuilder()Create a new fluent API builder to constructFixedLimitinstance.copy()Create a copy of this limit with the same configuration.static FixedLimitcreate()Create a new instance with all defaults (no limit).static FixedLimitcreate(FixedLimitConfig config) Create a new instance from configuration.static FixedLimitCreate a new instance from configuration.static FixedLimitCreate an instance from the provided semaphore.static FixedLimitcreate(Consumer<FixedLimitConfig.Builder> consumer) Create a new instance customizing its configuration.voidInvoke a runnable within the limits of this limiter.<T> TInvoke 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, 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.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.helidon.common.concurrency.limits.LimitAlgorithm
tryAcquire
-
Field Details
-
DEFAULT_LIMIT
public static final int DEFAULT_LIMITDefault limit, meaning unlimited execution.- See Also:
-
DEFAULT_QUEUE_LENGTH
public static final int DEFAULT_QUEUE_LENGTHDefault length of the queue.- See Also:
-
DEFAULT_QUEUE_TIMEOUT_DURATION
Timeout of a request that is enqueued.- See Also:
-
-
Method Details
-
builder
Create a new fluent API builder to constructFixedLimitinstance.- Returns:
- fluent API builder
-
create
Create a new instance with all defaults (no limit).- Returns:
- a new limit instance
-
create
Create an instance from the provided semaphore.- Parameters:
semaphore- semaphore to use- Returns:
- a new fixed limit backed by the provided semaphore
-
create
Create a new instance from configuration.- Parameters:
config- configuration of the fixed limit- Returns:
- a new limit instance configured from
config
-
create
Create a new instance from configuration.- Parameters:
config- configuration of the fixed 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:LimitAlgorithmInvoke a callable within the limits of this limiter.Limitimplementors 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 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:LimitAlgorithmInvoke a runnable within the limits of this limiter.Limitimplementors 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 interfaceLimitAlgorithm- Parameters:
runnable- runnable to execute within the limit- Throws:
Exception- in case the task failed with an exception
-
tryAcquire
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 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:SemaphoreLimitUnderlying semaphore of this limit.- Specified by:
semaphorein interfaceSemaphoreLimit- Returns:
- the semaphore instance
-
prototype
Description copied from interface:RuntimeType.ApiThe prototype as it was received when creating this runtime object instance.- Specified by:
prototypein interfaceRuntimeType.Api<FixedLimitConfig>- Returns:
- prototype object used to create this instance
-
name
Description copied from interface:NamedServiceName of this implementation, as provided inConfiguredProvider.create(Config, String).- Specified by:
namein interfaceNamedService- Returns:
- name of this service
-
type
Description 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 interfaceNamedService- Returns:
- type of this service
-
copy
Description copied from interface:LimitCreate a copy of this limit with the same configuration.
-