Class InMemoryConfigSource

java.lang.Object
cloud.opencode.base.config.source.InMemoryConfigSource
All Implemented Interfaces:
ConfigSource

public class InMemoryConfigSource extends Object implements 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 Details

    • InMemoryConfigSource

      public InMemoryConfigSource()
      Create empty in-memory config source 创建空的内存配置源
    • InMemoryConfigSource

      public InMemoryConfigSource(Map<String,String> properties)
      Create in-memory config source with initial properties 创建带初始属性的内存配置源
      Parameters:
      properties - initial properties | 初始属性
    • InMemoryConfigSource

      public InMemoryConfigSource(String name, Map<String,String> properties)
      Create named in-memory config source 创建命名的内存配置源
      Parameters:
      name - source name | 源名称
      properties - initial properties | 初始属性
  • Method Details

    • getName

      public String getName()
      Description copied from interface: ConfigSource
      Get configuration source name 获取配置源名称
      Specified by:
      getName in interface ConfigSource
      Returns:
      source name | 源名称
    • getProperties

      public Map<String,String> getProperties()
      Description copied from interface: ConfigSource
      Get all configuration properties 获取所有配置属性

      Performance | 性能:

      This method should return a cached immutable map for best performance.

      此方法应返回缓存的不可变映射以获得最佳性能。

      Specified by:
      getProperties in interface ConfigSource
      Returns:
      configuration properties map | 配置属性映射
    • getPriority

      public int getPriority()
      Description copied from interface: ConfigSource
      Get configuration source priority (higher number = higher priority) 获取配置源优先级(数值越大优先级越高)

      Default Priorities | 默认优先级:

      • CommandLine: 200
      • Environment: 100
      • Properties/YAML: 50
      • InMemory: 10
      Specified by:
      getPriority in interface ConfigSource
      Returns:
      priority value | 优先级值
    • setProperty

      public void setProperty(String key, String value)
      Set property value 设置属性值
      Parameters:
      key - property key | 属性键
      value - property value | 属性值
    • removeProperty

      public String removeProperty(String key)
      Remove property 移除属性
      Parameters:
      key - property key | 属性键
      Returns:
      previous value or null | 之前的值或null
    • setProperties

      public void setProperties(Map<String,String> props)
      Set multiple properties 设置多个属性
      Parameters:
      props - properties to set | 要设置的属性
    • clear

      public void clear()
      Clear all properties 清除所有属性