Update Design and Architecture
@@ -2,30 +2,40 @@
|
|||||||
|
|
||||||
## Motivation
|
## Motivation
|
||||||
|
|
||||||
- Provide an application-wide, strongly typed key-value store
|
- Provide an application-wide, strongly typed key-value store
|
||||||
- Avoid tight coupling of modules
|
- Avoid tight coupling of modules
|
||||||
- Allow subscribing to value changes without risking memory leaks
|
- Allow subscribing to value changes without risking memory leaks
|
||||||
|
- Support multiple independent named contexts for better modularity and isolation
|
||||||
|
|
||||||
## Why Enum Singleton
|
## Why Enum Singleton
|
||||||
|
|
||||||
- Simple
|
- Simple
|
||||||
- Thread-safe by Java specification
|
- Thread-safe by Java specification
|
||||||
- Cannot be duplicated through serialization
|
- 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
|
## Why Weak References for Listeners
|
||||||
|
|
||||||
- Listeners should not prevent GC
|
- Listeners should not prevent garbage collection
|
||||||
- Weak references automatically clean up when listener objects are unreachable
|
- Weak references automatically clean up when listener objects are unreachable
|
||||||
|
|
||||||
## Thread Safety
|
## Thread Safety
|
||||||
|
|
||||||
- Uses `ConcurrentHashMap`
|
- Uses `ConcurrentHashMap` for concurrent access
|
||||||
- Listeners stored in `CopyOnWriteArrayList`
|
- Listeners stored in `CopyOnWriteArrayList` for safe iteration
|
||||||
|
|
||||||
## Trade-offs
|
## Trade-offs
|
||||||
|
|
||||||
- Slightly higher cost for weak-reference listener lookups
|
- Slightly higher cost for weak-reference listener lookups
|
||||||
- Enum cannot be extended (intentional for safe singleton)
|
- Enum cannot be extended (intentional for safe singleton)
|
||||||
|
- Multi-context adds minimal complexity but greatly improves flexibility
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[[Home]] | [[Programming Guide]] | [[API Reference]] | [[FAQ]] | [[Contributing]]
|
[[Home]] | [[Programming Guide]] | [[API Reference]] | [[FAQ]] | [[Contributing]]
|
||||||
Reference in New Issue
Block a user