Package com.atlassian.bamboo.utils
Class InvocationLimiter<T>
- java.lang.Object
-
- com.atlassian.bamboo.utils.InvocationLimiter<T>
-
- Type Parameters:
T
- result type
@ThreadSafe public class InvocationLimiter<T> extends Object
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:
InvocationLimiterResponse
-
-
Constructor Summary
Constructors Constructor Description InvocationLimiter(int invocationLimit, int invocationLimitUnitCount, @NotNull TimeUnit invocationLimitUnit)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <V> @NotNull InvocationLimiterResponse<V>
invoke(T resource, @NotNull Supplier<V> invocation)
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 Detail
-
InvocationLimiter
public InvocationLimiter(int invocationLimit, int invocationLimitUnitCount, @NotNull @NotNull TimeUnit invocationLimitUnit)
-
-
Method Detail
-
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
-
-