Module bus.limiter

Class RequestProvider

java.lang.Object
org.miaixz.bus.limiter.metric.RequestProvider
All Implemented Interfaces:
Serializable, org.miaixz.bus.core.Provider, Provider

public class RequestProvider extends Object implements 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 Details

    • RequestProvider

      public RequestProvider()
  • Method Details

    • setMarkSupplier

      public void setMarkSupplier(Supplier supplier)
      Sets a new user identifier provider. This allows customizing how user identifiers are obtained for request limiting.
      Parameters:
      supplier - The new Supplier to be used for providing user identifiers.
    • get

      public StrategyMode get()
      Returns the strategy mode supported by this provider, which is StrategyMode.REQUEST_LIMIT.
      Specified by:
      get in interface Provider
      Returns:
      The StrategyMode.REQUEST_LIMIT enum value.
    • process

      public Object process(Object bean, Method method, Object[] args)
      Processes the method invocation by applying request limiting rules. It retrieves the current user identifier, obtains or creates a ResourceManager for that user, and then checks if the request is allowed based on the Limiting annotation configured for the method. If the request is blocked, the Supplier.intercept(Object, Method, Object[]) method is called.
      Specified by:
      process in interface Provider
      Parameters:
      bean - The target object on which the method is invoked.
      method - The Method being 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.