Class InMemoryConfigSource
java.lang.Object
cloud.opencode.base.config.source.InMemoryConfigSource
- All Implemented Interfaces:
ConfigSource
In-Memory Configuration Source
内存配置源
Stores configuration in memory with support for runtime updates and programmatic configuration.
在内存中存储配置,支持运行时更新和编程配置。
Features | 主要功能:
- Programmatic configuration - 编程配置
- Runtime updates - 运行时更新
- Thread-safe mutations - 线程安全的修改
- Low priority (10) - 低优先级(10)
Usage Examples | 使用示例:
// From map
Map<String, String> props = Map.of(
"app.name", "MyApp",
"server.port", "8080"
);
InMemoryConfigSource source = new InMemoryConfigSource(props);
// Runtime updates
source.setProperty("server.port", "9090");
source.removeProperty("old.key");
// Bulk update
source.setProperties(Map.of("key1", "val1", "key2", "val2"));
Performance | 性能特性:
- Time complexity: O(1) for get/set - 时间复杂度: 获取/设置为O(1)
- Thread-safe concurrent access - 线程安全的并发访问
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Mutable source - 可变源
- Since:
- JDK 25, opencode-base-config V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreate empty in-memory config source 创建空的内存配置源InMemoryConfigSource(String name, Map<String, String> properties) Create named in-memory config source 创建命名的内存配置源InMemoryConfigSource(Map<String, String> properties) Create in-memory config source with initial properties 创建带初始属性的内存配置源 -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear all properties 清除所有属性getName()Get configuration source name 获取配置源名称intGet configuration source priority (higher number = higher priority) 获取配置源优先级(数值越大优先级越高)Get all configuration properties 获取所有配置属性removeProperty(String key) Remove property 移除属性voidsetProperties(Map<String, String> props) Set multiple properties 设置多个属性voidsetProperty(String key, String value) Set property value 设置属性值Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ConfigSource
getProperty, reload, supportsReload
-
Constructor Details
-
InMemoryConfigSource
public InMemoryConfigSource()Create empty in-memory config source 创建空的内存配置源 -
InMemoryConfigSource
-
InMemoryConfigSource
-
-
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 | 优先级值
-
setProperty
-
removeProperty
-
setProperties
-
clear
public void clear()Clear all properties 清除所有属性
-