Interface ConfigListener
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Configuration Change Listener
配置变更监听器
Functional interface for listening to configuration changes. Implementations can react to configuration modifications, additions, and removals.
用于监听配置变更的函数式接口。实现类可以响应配置的修改、添加和删除。
Features | 主要功能:
- Functional interface for configuration change callbacks - 配置变更回调的函数式接口
- Supports lambda expressions - 支持Lambda表达式
- Asynchronous notification support - 支持异步通知
Usage Examples | 使用示例:
// Lambda listener
config.addListener(event -> {
System.out.println("Config changed: " + event.key());
});
// Method reference
config.addListener(this::handleConfigChange);
// Specific key listener
config.addListener("log.level", event -> {
updateLogLevel(event.newValue());
});
// Multi-event handler
config.addListener(event -> {
if (event.isModified() && event.key().startsWith("database.")) {
refreshDataSource();
}
});
Performance | 性能特性:
- Listener execution may be async - 监听器执行可能是异步的
- Keep listener logic lightweight - 保持监听器逻辑轻量级
Security | 安全性:
- Thread-safe: Implementation-dependent - 线程安全: 取决于实现
- Exception handling: Exceptions are caught and logged - 异常处理: 异常会被捕获并记录
- Since:
- JDK 25, opencode-base-config V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidonConfigChange(ConfigChangeEvent event) Handle configuration change event 处理配置变更事件
-
Method Details
-
onConfigChange
Handle configuration change event 处理配置变更事件Examples | 示例:
// Print change event -> System.out.println(event) // Update component event -> component.refresh() // Conditional handling event -> { if (event.isModified()) { handleModification(event); } }- Parameters:
event- configuration change event | 配置变更事件
-