Module bus.limiter

Class ByteBuddyHandler

java.lang.Object
org.miaixz.bus.limiter.proxy.ByteBuddyHandler
All Implemented Interfaces:
InvocationHandler

public class ByteBuddyHandler extends Object implements InvocationHandler
An InvocationHandler implementation that intercepts method calls to apply limiting rules based on annotations. This handler integrates with ByteBuddy for proxying and uses Sentinel for enforcing various limiting strategies like downgrade, hotspot, and request limiting.
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • ByteBuddyHandler

      public ByteBuddyHandler(ByteBuddyProxy byteBuddyProxy)
      Constructs a new ByteBuddyHandler with the specified ByteBuddyProxy.
      Parameters:
      byteBuddyProxy - The ByteBuddyProxy instance containing the target object.
  • Method Details

    • invoke

      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
      Intercepts method invocations and applies limiting rules if the method is configured for it. It resolves the real method, checks for registered limiting annotations, and then delegates to Sentinel to process the method according to the defined strategy.
      Specified by:
      invoke in interface InvocationHandler
      Parameters:
      proxy - The proxy instance that the method was invoked on.
      method - The Method instance corresponding to the interface method invoked on the proxy instance.
      args - An array of objects containing the values of the arguments passed in the method invocation on the proxy instance. If an interface method has no arguments, this array will be empty. If the method is a static method, this array will be null.
      Returns:
      The result of the method invocation, potentially modified by limiting strategies.
      Throws:
      Throwable - if an exception occurs during method invocation or limiting processing.
      RuntimeException - if an unsupported annotation type is encountered.