From d39b9c2be48341ef71b7d2a0789199ab5679eb58 Mon Sep 17 00:00:00 2001 From: Leo Galambos Date: Tue, 8 Jul 2025 21:27:22 +0200 Subject: [PATCH] Update Design and Architecture --- Design-and-Architecture.md | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/Design-and-Architecture.md b/Design-and-Architecture.md index 66dadc6..76941ce 100644 --- a/Design-and-Architecture.md +++ b/Design-and-Architecture.md @@ -2,30 +2,40 @@ ## Motivation -- Provide an application-wide, strongly typed key-value store -- Avoid tight coupling of modules -- Allow subscribing to value changes without risking memory leaks +- Provide an application-wide, strongly typed key-value store +- Avoid tight coupling of modules +- Allow subscribing to value changes without risking memory leaks +- Support multiple independent named contexts for better modularity and isolation ## Why Enum Singleton -- Simple -- Thread-safe by Java specification -- Cannot be duplicated through serialization +- Simple +- Thread-safe by Java specification +- Cannot be duplicated through serialization + +## Multi-Context Extension + +- `Ctx` manages multiple named contexts identified by strings +- Each named context is an independent key-value store with its own listeners +- Enables modular, isolated state management within the same application +- Backwards compatible: default context operations still available via `Ctx.INSTANCE` ## Why Weak References for Listeners -- Listeners should not prevent GC -- Weak references automatically clean up when listener objects are unreachable +- Listeners should not prevent garbage collection +- Weak references automatically clean up when listener objects are unreachable ## Thread Safety -- Uses `ConcurrentHashMap` -- Listeners stored in `CopyOnWriteArrayList` +- Uses `ConcurrentHashMap` for concurrent access +- Listeners stored in `CopyOnWriteArrayList` for safe iteration ## Trade-offs -- Slightly higher cost for weak-reference listener lookups -- Enum cannot be extended (intentional for safe singleton) +- Slightly higher cost for weak-reference listener lookups +- Enum cannot be extended (intentional for safe singleton) +- Multi-context adds minimal complexity but greatly improves flexibility --- + [[Home]] | [[Programming Guide]] | [[API Reference]] | [[FAQ]] | [[Contributing]] \ No newline at end of file