Configuration Sources

Configuration sources are pluggable providers that load dynamic variable values into the DynamicExpressionRegistry at application startup. The system supports multiple sources with a precedence mechanism.

Overview

The ConfigurableValueSource interface defines how values are loaded from external sources:

public interface ConfigurableValueSource {
    String getName();
    List<ConfigurableValue> getValues();
    Integer getPrecedence();
}

Each source provides:

  • A name for identification and logging

  • A list of configurable values (global and/or entity-scoped)

  • A precedence level that determines processing order

ConfigurableValue Types

Configuration sources return instances of ConfigurableValue (or its subclass ScopedConfigurableValue).

ConfigurableValue (Global)

Represents a global configuration value:

public class ConfigurableValue {
    private String key;     // e.g., "paymentService_upperBound"
    private Object value;   // e.g., 5000

    public boolean isScoped() {
        return false;  // Global values
    }
}

ScopedConfigurableValue (Entity-Scoped)

Extends ConfigurableValue to add entity association:

@Data
public class ScopedConfigurableValue extends ConfigurableValue {
    private ProcessingEntity processingEntity;

    public ScopedConfigurableValue(String key, Object value, ProcessingEntity processingEntity) {
        super(key, value);
        this.processingEntity = Objects.requireNonNull(processingEntity, "ProcessingEntity is required");
    }

    @Override
    public boolean isScoped() {
        return true;  // Entity-scoped values
    }
}

Precedence System

Multiple configuration sources can be registered, and the precedence determines the order in which they are applied. Higher precedence values win - they are processed later and overwrite earlier values.

Processing order:

    Low precedence ──────────────────────> High precedence
         │                                        │
         v                                        v
    HOCON file                            Dynamic Settings
    (precedence: 5)                       (precedence: 10)

If both set "paymentService_upperBound":
    - HOCON sets 1000 (processed first)
    - Dynamic Settings sets 5000 (processed later, wins)
    - Final value: 5000

Default Precedence Levels

The system defines standard precedence constants:

public interface ConfigurableValueSource {
    Integer PRECEDENCE_HOCON = 5;           // Static configuration files
    Integer PRECEDENCE_DYNAMIC_SETTINGS = 10; // Runtime/database settings
}

This ordering means:

  1. HOCON files provide base configuration

  2. Dynamic settings can override for environment-specific adjustments