Interface SharedState
public interface SharedState
Thread-safe key-value store for sharing state between scripts.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all stored key-value pairs.booleancontainsKey(String key) Checks whether a value is stored under the given key.Retrieves the value stored under the given key.default <T> TRetrieves and casts the value stored under the given key.voidStores a value under the given key, replacing any existing value.Removes the value stored under the given key.snapshot()Returns an immutable snapshot of all key-value pairs currently stored.
-
Method Details
-
put
Stores a value under the given key, replacing any existing value.The store holds a bounded number of distinct keys. Once full it keeps accepting overwrites of keys it already has but drops writes that would introduce a new one, so a runaway script cannot exhaust the host's heap. Reaching the bound is a bug in the writer, not a state to design around.
- Parameters:
key- the key to store the value undervalue- the value to store
-
get
-
get
Retrieves and casts the value stored under the given key.This is the prescribed typed-key recovery idiom for the script blackboard: the store remains heterogeneous-by-design, but the lookup recovers the narrow type at the call site via the supplied class token.
- Type Parameters:
T- the expected value type- Parameters:
key- the key to look uptype- the expected class of the value- Returns:
- the stored value cast to
T, ornullif not present or not an instance oftype
-
remove
-
containsKey
Checks whether a value is stored under the given key.- Parameters:
key- the key to check- Returns:
trueif a value exists for the key
-
snapshot
-
clear
void clear()Removes all stored key-value pairs.
-