java.lang.Object
org.miaixz.bus.limiter.metric.RequestProvider
- All Implemented Interfaces:
Serializable,org.miaixz.bus.core.Provider,Provider
Implements the
Provider interface for handling the REQUEST_LIMIT strategy mode. This provider manages request
limiting based on user identifiers and configured Limiting annotations. It uses a ResourceManager for
each user to track and enforce limits.- Since:
- Java 17+
- Author:
- Kimi Liu
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionget()Returns the strategy mode supported by this provider, which isStrategyMode.REQUEST_LIMIT.Processes the method invocation by applying request limiting rules.voidsetMarkSupplier(Supplier supplier) Sets a new user identifier provider.
-
Constructor Details
-
RequestProvider
public RequestProvider()
-
-
Method Details
-
setMarkSupplier
Sets a new user identifier provider. This allows customizing how user identifiers are obtained for request limiting.- Parameters:
supplier- The newSupplierto be used for providing user identifiers.
-
get
Returns the strategy mode supported by this provider, which isStrategyMode.REQUEST_LIMIT.- Specified by:
getin interfaceProvider- Returns:
- The
StrategyMode.REQUEST_LIMITenum value.
-
process
Processes the method invocation by applying request limiting rules. It retrieves the current user identifier, obtains or creates aResourceManagerfor that user, and then checks if the request is allowed based on theLimitingannotation configured for the method. If the request is blocked, theSupplier.intercept(Object, Method, Object[])method is called.- Specified by:
processin interfaceProvider- Parameters:
bean- The target object on which the method is invoked.method- TheMethodbeing invoked.args- The arguments passed to the method invocation.- Returns:
- The result of the method invocation if allowed, or the result of the interception if blocked.
-