Package net.storm.api.plugins.config
Class ConfigInvocationHandler
java.lang.Object
net.storm.api.plugins.config.ConfigInvocationHandler
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionConfigInvocationHandler(ConfigManager manager) Creates a new invocation handler using the specified config manager. -
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectcallDefaultMethod(Object proxy, Method method, Object[] args) Invokes a default method on a proxy object.voidInvalidates all cached configuration values.Handles method invocations on the configuration proxy.
-
Constructor Details
-
ConfigInvocationHandler
Creates a new invocation handler using the specified config manager.- Parameters:
manager- the ConfigManager for reading and writing configuration values
-
-
Method Details
-
callDefaultMethod
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 objectmethod- the default method to invokeargs- the method arguments- Returns:
- the result of the default method
- Throws:
Throwable- if the method invocation fails
-
invoke
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:
invokein interfaceInvocationHandler- Parameters:
proxy- the proxy instancemethod- the method being invokedargs- 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.
-