Class CompositeConfigSource
java.lang.Object
cloud.opencode.base.config.source.CompositeConfigSource
- All Implemented Interfaces:
ConfigSource
Composite Configuration Source
组合配置源
Combines multiple configuration sources with priority-based merging. Higher priority sources override lower priority ones.
组合多个配置源并基于优先级合并。高优先级源覆盖低优先级源。
Features | 主要功能:
- Priority-based merging - 基于优先级的合并
- Multiple source aggregation - 多源聚合
- Automatic source ordering - 自动源排序
- Hot reload support - 热重载支持
Usage Examples | 使用示例:
List<ConfigSource> sources = List.of(
new PropertiesConfigSource("defaults.properties"), // Priority: 50
new EnvironmentConfigSource(), // Priority: 100
new CommandLineConfigSource(args) // Priority: 200
);
CompositeConfigSource composite = new CompositeConfigSource(sources);
// Command line > Environment > Properties
Priority Order | 优先级顺序:
Higher number = Higher priority 200: Command Line 100: Environment Variables 50: Properties/YAML files 10: In-Memory defaults
Performance | 性能特性:
- Time complexity: O(n*m) for merging - 时间复杂度: 合并为O(n*m)
- Merged map cached - 合并的映射被缓存
- Reload triggers re-merge - 重载触发重新合并
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Immutable merged properties - 不可变的合并属性
- Since:
- JDK 25, opencode-base-config V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCompositeConfigSource(List<ConfigSource> sources) Create composite config source 创建组合配置源 -
Method Summary
Modifier and TypeMethodDescriptiongetName()Get configuration source name 获取配置源名称intGet configuration source priority (higher number = higher priority) 获取配置源优先级(数值越大优先级越高)Get all configuration properties 获取所有配置属性Get all underlying sources 获取所有底层源voidreload()Reload configuration from source 从源重新加载配置booleanCheck if source supports hot reload 检查源是否支持热重载Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ConfigSource
getProperty
-
Constructor Details
-
CompositeConfigSource
Create composite config source 创建组合配置源- Parameters:
sources- configuration sources | 配置源列表
-
-
Method Details
-
getName
Description copied from interface:ConfigSourceGet configuration source name 获取配置源名称- Specified by:
getNamein interfaceConfigSource- Returns:
- source name | 源名称
-
getProperties
Description copied from interface:ConfigSourceGet all configuration properties 获取所有配置属性Performance | 性能:
This method should return a cached immutable map for best performance.
此方法应返回缓存的不可变映射以获得最佳性能。
- Specified by:
getPropertiesin interfaceConfigSource- Returns:
- configuration properties map | 配置属性映射
-
getPriority
public int getPriority()Description copied from interface:ConfigSourceGet configuration source priority (higher number = higher priority) 获取配置源优先级(数值越大优先级越高)Default Priorities | 默认优先级:
- CommandLine: 200
- Environment: 100
- Properties/YAML: 50
- InMemory: 10
- Specified by:
getPriorityin interfaceConfigSource- Returns:
- priority value | 优先级值
-
supportsReload
public boolean supportsReload()Description copied from interface:ConfigSourceCheck if source supports hot reload 检查源是否支持热重载- Specified by:
supportsReloadin interfaceConfigSource- Returns:
- true if hot reload supported | 如果支持热重载返回true
-
reload
public void reload()Description copied from interface:ConfigSourceReload configuration from source 从源重新加载配置This method is called when hot reload is enabled.
启用热重载时会调用此方法。
- Specified by:
reloadin interfaceConfigSource
-
getSources
Get all underlying sources 获取所有底层源- Returns:
- list of sources | 源列表
-