DynamicExpressionRegistry and Scopes

The DynamicExpressionRegistry is a singleton that stores and retrieves dynamic variable values at runtime. It supports multiple scopes for flexible configuration management.

Overview

The registry serves as the central storage for all configured dynamic variable values. When generated business rules code executes, it queries the registry to resolve variable values.

Key characteristics:

  • Singleton pattern - one global instance accessible throughout the application

  • Two-tier storage - global registry plus entity-scoped registries

  • Thread-safe - uses ConcurrentHashMap for concurrent access

  • Type-safe retrieval - returns values typed according to DynamicVariable<T> definitions

Registry Scopes

Global Scope

Global values are available to all executions and are typically set at application startup from configuration sources.

// Register a global value
DynamicExpressionRegistry.getInstance().register("paymentService_upperBound", 5000);

// Or using the type-safe API
DynamicExpressionRegistry.getInstance().register(
    PaymentServiceVariables.upperBound,
    BigInteger.valueOf(5000)
);

Entity Scope

Entity-scoped values are associated with a specific ProcessingEntity and override global values for that context. This is useful for per-entity configuration.

ProcessingEntity entity = ...; // from ProcessingContext

// Register an entity-scoped value
DynamicExpressionRegistry.getInstance().register(
    entity,
    "paymentService_upperBound",
    10000
);

Resolution Precedence

When resolving a dynamic variable value, the registry follows this precedence:

  1. Entity-scoped value (if a ProcessingContext is available)

  2. Global value

  3. Default value (from the DynamicVariable definition, defined in MPS)

This allows applications to set sensible global defaults while overriding specific values for particular processing contexts.

Thread Safety

The registry is designed for concurrent access:

  • Global registry uses ConcurrentHashMap

  • Entity-scoped registries use nested ConcurrentHashMap structures

  • Registration and retrieval operations are atomic

This makes it safe to register values from multiple threads and resolve them concurrently during parallel processing.