Interface ConfigSource
- All Known Implementing Classes:
CommandLineConfigSource, CompositeConfigSource, EnvironmentConfigSource, InMemoryConfigSource, PropertiesConfigSource, SystemPropertiesConfigSource, YamlConfigSource
public interface ConfigSource
Configuration Source Interface
配置源接口
Represents a source of configuration properties. Implementations can load configuration from various sources like files, environment variables, system properties, databases, etc.
表示配置属性的来源。实现类可以从文件、环境变量、系统属性、数据库等各种源加载配置。
Features | 主要功能:
- Configuration source abstraction - 配置源抽象
- Priority-based source ordering - 基于优先级的源排序
- Hot reload support - 热重载支持
- SPI extensibility - SPI扩展性
Usage Examples | 使用示例:
// Implement custom source
public class DatabaseConfigSource implements ConfigSource {
@Override
public String getName() {
return "database";
}
@Override
public Map<String, String> getProperties() {
return loadFromDatabase();
}
@Override
public int getPriority() {
return 75; // Between properties and environment
}
}
// Use in builder
Config config = OpenConfig.builder()
.addSource(new DatabaseConfigSource())
.build();
Performance | 性能特性:
- getProperties() should be cached - getProperties()应该被缓存
- Reload should check modification time - 重载应检查修改时间
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Immutable properties map recommended - 推荐使用不可变属性映射
- Since:
- JDK 25, opencode-base-config V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiongetName()Get configuration source name 获取配置源名称default intGet configuration source priority (higher number = higher priority) 获取配置源优先级(数值越大优先级越高)Get all configuration properties 获取所有配置属性default StringgetProperty(String key) Get configuration value by key 根据键获取配置值default voidreload()Reload configuration from source 从源重新加载配置default booleanCheck if source supports hot reload 检查源是否支持热重载
-
Method Details
-
getName
-
getProperties
-
getProperty
-
getPriority
default int getPriority()Get configuration source priority (higher number = higher priority) 获取配置源优先级(数值越大优先级越高)Default Priorities | 默认优先级:
- CommandLine: 200
- Environment: 100
- Properties/YAML: 50
- InMemory: 10
- Returns:
- priority value | 优先级值
-
supportsReload
default boolean supportsReload()Check if source supports hot reload 检查源是否支持热重载- Returns:
- true if hot reload supported | 如果支持热重载返回true
-
reload
default void reload()Reload configuration from source 从源重新加载配置This method is called when hot reload is enabled.
启用热重载时会调用此方法。
-