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
ConcurrentHashMapfor 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:
-
Entity-scoped value (if a
ProcessingContextis available) -
Global value
-
Default value (from the
DynamicVariabledefinition, 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
ConcurrentHashMapstructures -
Registration and retrieval operations are atomic
This makes it safe to register values from multiple threads and resolve them concurrently during parallel processing.