Package cloud.opencode.base.config.jdk25
package cloud.opencode.base.config.jdk25
JDK 25 Enhanced Features Package
JDK 25增强特性包
This package provides advanced configuration features leveraging JDK 25 language and API enhancements.
此包提供利用JDK 25语言和API增强的高级配置特性。
Features | 主要功能:
- Record configuration binding - Record配置绑定
- Sealed configuration source types - 密封配置源类型
- Virtual thread hot reload - 虚拟线程热更新
- ScopedValue configuration context - ScopedValue配置上下文
- Reactive configuration values - 响应式配置值
- Pattern matching for configuration - 配置的模式匹配
Components | 组件:
ConfigSourceType- Sealed source types - 密封配置源类型ConfigSourceProcessor- Pattern matching processor - 模式匹配处理器ConfigContext- ScopedValue context - ScopedValue上下文ContextAwareConfig- Context-aware configuration - 上下文感知配置VirtualThreadConfigWatcher- Virtual thread watcher - 虚拟线程监视器ReactiveConfigValue- Reactive config values - 响应式配置值Required- Required annotation for Records - Record必填注解DefaultValue- Default value annotation for Records - Record默认值注解
Record Binding Example | Record绑定示例:
record DatabaseConfig(
@Required String url,
@Required String username,
@Required String password,
@DefaultValue("10") int maxPoolSize,
@DefaultValue("30s") Duration connectionTimeout,
PoolConfig pool
) {}
DatabaseConfig config = OpenConfig.bind("database", DatabaseConfig.class);
ScopedValue Context Example | ScopedValue上下文示例:
ConfigContext.withTenant("tenant-1", () -> {
// Configuration reads prioritize tenant-specific values
String apiKey = OpenConfig.getString("api.key");
return processRequest(request, apiKey);
});
ConfigContext.withOverrides(Map.of("database.url", "jdbc:h2:mem:test"), () -> {
// Temporary configuration override for testing
runTests();
return null;
});
Reactive Configuration Example | 响应式配置示例:
ReactiveConfigValue<String> logLevel = ReactiveConfigValue
.ofString(config, "log.level")
.subscribe(level -> updateLogLevel(level));
// When config changes, subscriber is notified automatically
String current = logLevel.get();
- Since:
- JDK 25, opencode-base-config V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
ClassDescriptionConfiguration Context using JDK 25 Scoped Values 使用JDK 25作用域值的配置上下文Configuration Source Processor with Pattern Matching 配置源处理器(使用模式匹配)Sealed Configuration Source Type for JDK 25 JDK 25的密封配置源类型Context-Aware Configuration 上下文感知配置Default Value Annotation for Record Components Record组件的默认值注解Reactive Configuration Value 响应式配置值Required Configuration Annotation for Record Components Record组件的必填配置注解Virtual Thread Configuration Watcher 虚拟线程配置监视器