Package com.atlassian.bamboo.utils
Class InvocationLimiter<T>
java.lang.Object
com.atlassian.bamboo.utils.InvocationLimiter<T>
- Type Parameters:
T
- result type
Limits number of invocations of some resource. Limit is enforced per an arbitrary resource key.
Concurrent access to the same resource is allowed. In case of reaching the limit of invocation in a period of time, the result will contain information when the next invocation can be performed for this resource.
- See Also:
-
Constructor Summary
ConstructorDescriptionInvocationLimiter
(int invocationLimit, int invocationLimitUnitCount, @NotNull TimeUnit invocationLimitUnit) -
Method Summary
Modifier and TypeMethodDescription<V> @NotNull InvocationLimiterResponse<V>
Try to invoke a given resource.void
resetSettings
(int limit, int invocationLimitUnitCount, @NotNull TimeUnit invocationLimitUnit) Resets settings for limiter, removes all data about past invocation and start counting invocation from 0.
-
Constructor Details
-
InvocationLimiter
public InvocationLimiter(int invocationLimit, int invocationLimitUnitCount, @NotNull @NotNull TimeUnit invocationLimitUnit)
-
-
Method Details
-
invoke
@NotNull public <V> @NotNull InvocationLimiterResponse<V> invoke(@NotNull T resource, @NotNull @NotNull Supplier<V> invocation) Try to invoke a given resource. In case of reaching the maximum number of calls, the response will contain information when the next call can be done.- Type Parameters:
V
- type of response- Parameters:
resource
- key of the resource for which to measure invocationsinvocation
- action which should be invoked- Returns:
- wrapper with information if invocation has been performed or rejected
-
resetSettings
public void resetSettings(int limit, int invocationLimitUnitCount, @NotNull @NotNull TimeUnit invocationLimitUnit) Resets settings for limiter, removes all data about past invocation and start counting invocation from 0.- Parameters:
limit
- new limitinvocationLimitUnitCount
- new limit unit countinvocationLimitUnit
- new limit unit
-