Update API Reference
@@ -4,17 +4,28 @@ This page summarizes the key classes in **Conflux**.
|
||||
|
||||
## Ctx
|
||||
|
||||
- `put(Key<T>, T value)` — store or update a value for a key
|
||||
- `get(Key<T>)` — retrieve a value
|
||||
- `contains(Key<?>)` — check if a key is present
|
||||
- `remove(Key<?>)` — remove a key and its listeners
|
||||
- `clear()` — remove everything
|
||||
- `addListener(Key<T>, Listener<T>)` — register a weakly referenced listener
|
||||
- `removeListener(Key<T>, Listener<T>)` — remove a listener
|
||||
`Ctx` is a singleton enum that serves as the primary access point for the default application-wide context. It also supports managing multiple independent named contexts.
|
||||
|
||||
### Default Context Operations
|
||||
|
||||
- `put(Key<T>, T value)` — store or update a value for a key in the default context
|
||||
- `get(Key<T>)` — retrieve a value from the default context
|
||||
- `contains(Key<?>)` — check if a key is present in the default context
|
||||
- `remove(Key<?>)` — remove a key and its listeners from the default context
|
||||
- `clear()` — clear all keys and listeners from the default context
|
||||
- `addListener(Key<T>, Listener<T>)` — register a weakly referenced listener in the default context
|
||||
- `removeListener(Key<T>, Listener<T>)` — remove a listener from the default context
|
||||
|
||||
### Managing Multiple Named Contexts
|
||||
|
||||
- `getContext(String name)` — retrieve or create a named independent context implementing `CtxInterface`
|
||||
- `contextNames()` — returns the set of existing named context keys
|
||||
|
||||
Each named context functions independently with its own keys, values, and listeners, allowing isolated storage scopes within the same application.
|
||||
|
||||
## Key
|
||||
|
||||
A strongly typed key:
|
||||
A strongly typed key used to identify context entries:
|
||||
|
||||
```java
|
||||
Key<String> nameKey = new Key<>("name", String.class);
|
||||
@@ -23,9 +34,11 @@ Key<String> nameKey = new Key<>("name", String.class);
|
||||
* `name()` returns the key name
|
||||
* `type()` returns the key type
|
||||
|
||||
Keys ensure type consistency and prevent accidental type mismatches.
|
||||
|
||||
## Listener
|
||||
|
||||
An interface for change notifications:
|
||||
An interface for receiving notifications on value changes:
|
||||
|
||||
```java
|
||||
public interface Listener<T> {
|
||||
@@ -33,7 +46,7 @@ public interface Listener<T> {
|
||||
}
|
||||
```
|
||||
|
||||
Registered listeners will be weakly referenced and called on value change.
|
||||
Listeners are weakly referenced to avoid memory leaks and invoked whenever the corresponding key's value changes.
|
||||
|
||||
---
|
||||
[[Home]] | [[Programming Guide]] | [[Design and Architecture]] | [[FAQ]] | [[Contributing]]
|
||||
[[Home]] | [[Programming Guide]] | [[Design and Architecture]] | [[FAQ]] | [[Contributing]]
|
||||
|
||||
Reference in New Issue
Block a user