Class ConfigInvocationHandler

java.lang.Object
net.storm.api.plugins.config.ConfigInvocationHandler
All Implemented Interfaces:
InvocationHandler

public class ConfigInvocationHandler extends Object implements InvocationHandler
Invocation handler that provides the implementation for configuration proxy interfaces.

ConfigInvocationHandler implements Java's InvocationHandler to create dynamic proxies for Config interfaces. When a configuration method is called on a proxy, this handler intercepts the call and:

  • For getters (no arguments): Retrieves the value from ConfigManager
  • For setters (one argument): Stores the value through ConfigManager
  • Handles caching to improve performance
  • Falls back to default method implementations when values are not set

See Also:
  • Constructor Details

    • ConfigInvocationHandler

      public ConfigInvocationHandler(ConfigManager manager)
      Creates a new invocation handler using the specified config manager.
      Parameters:
      manager - the ConfigManager for reading and writing configuration values
  • Method Details

    • callDefaultMethod

      public static Object callDefaultMethod(Object proxy, Method method, Object[] args) throws Throwable
      Invokes a default method on a proxy object.

      This uses MethodHandle to call the default implementation defined in the configuration interface.

      Parameters:
      proxy - the proxy object
      method - the default method to invoke
      args - the method arguments
      Returns:
      the result of the default method
      Throws:
      Throwable - if the method invocation fails
    • invoke

      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
      Handles method invocations on the configuration proxy.

      This method intercepts all calls to the proxy and routes them appropriately:

      • toString, hashCode, equals - standard Object methods
      • Methods with no arguments - configuration getters
      • Methods with one argument - configuration setters

      Specified by:
      invoke in interface InvocationHandler
      Parameters:
      proxy - the proxy instance
      method - the method being invoked
      args - the method arguments
      Returns:
      the result of the method invocation
      Throws:
      Throwable - if the invocation fails
    • invalidate

      public void invalidate()
      Invalidates all cached configuration values.

      This should be called when configuration values may have changed externally, such as after a profile switch or configuration import.