feat: add Configuration.withOptions for copy-on-write derivation#158
feat: add Configuration.withOptions for copy-on-write derivation#158OmarAlJarrah wants to merge 1 commit into
Conversation
Introduce an ergonomic way to derive a lightly-reconfigured Configuration without mutating the original. Configuration.withOptions(Consumer<Builder>) applies a builder mutator to a copy and returns a new immutable instance; Configuration.toBuilder() exposes the same prefilled builder for callers that prefer to thread it through other builder-folding code. This settles the open question of unified, cloneable client config: the layered Configuration is the single client-config type, so it gains the clone-and-reconfigure entry points rather than introducing a parallel one. ConfigurationBuilder now implements Builder<Configuration> and gains a constructor preloaded from an existing Configuration. Derivation is copy-on-write in the value sense: the override map is copied so the original and the derived instance never alias mutable state, while the env/system-property lookup seams are shared by reference (they are pure read functions and never mutated). The immutability semantics are documented in the Configuration KDoc. Closes #60
|
This adds copy-on-write derivation to the runtime IssuesPrefilled-builder accessor named |
|
Superseded by #161, which delivers the same copy-on-write derivation on
|
Summary
There was no ergonomic way to derive a lightly-reconfigured client configuration. This adds a copy-on-write derivation API on the existing layered
Configuration, which is the SDK's single client-config type, settling the open question of whether to introduce a unified cloneable config: it gains the clone-and-reconfigure entry points rather than spawning a parallel type.Changes
Configuration.withOptions(Consumer<ConfigurationBuilder>)— applies a builder mutator to a copy prefilled from the receiver and returns a new immutableConfiguration. The original is left unchanged.Configuration.toBuilder()— returns the same prefilledConfigurationBuilderfor callers that prefer to thread it through other builder-folding code beforebuild().ConfigurationBuildernow implementsBuilder<Configuration>and has a constructor preloaded from an existingConfiguration.Immutability semantics (decision note)
Derivation is copy-on-write in the value sense: the override map is copied up front, so the original and the derived instance never alias the same mutable state. The env / system-property lookup seams are shared by reference because they are pure read functions and are never mutated. An empty mutator yields an independent instance equal in behaviour to the original. This is documented in the
ConfigurationKDoc.Tests
Added coverage in
ConfigurationTestproving: derived copies pick up new and overridden keys; the original is never mutated (including the two-independent-derivations case); inherited env/property seams still resolve on the copy; andtoBuilder()is independent of the source after the fact.Gated build (scoped, run locally)
Closes #60