Class MemoryStateStore
java.lang.Object
com.wualabs.qtsurfer.engine.core.state.MemoryStateStore
- All Implemented Interfaces:
StateStore
KV on memory State store implementation
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()<T> TgetOrCreateState(String key, Supplier<T> factory) Atomic lazy creation viaConcurrentHashMap.computeIfAbsent(K, Function): two threads racing the firstinc()/add()on a key are guaranteed the SAME counter/accumulator instance.<T> T<T> voidSets a state value for the given key.toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface StateStore
add, clear, dec, getAccumulator, getCounter, getState, has, inc, is, reset, set, set, unset
-
Constructor Details
-
MemoryStateStore
public MemoryStateStore()
-
-
Method Details
-
setState
Sets a state value for the given key. If value is null, the key is removed from the store. Uses a ConcurrentHashMap for thread-safe access.- Specified by:
setStatein interfaceStateStore- Parameters:
key- the state keyvalue- the value to store, or null to remove the key
-
getState
- Specified by:
getStatein interfaceStateStore
-
getOrCreateState
Atomic lazy creation viaConcurrentHashMap.computeIfAbsent(K, Function): two threads racing the firstinc()/add()on a key are guaranteed the SAME counter/accumulator instance. The interface's default (check-then-put) could hand each racer its own instance, losing the increments applied to the discarded one — despite the accessors' documented thread-safety.- Specified by:
getOrCreateStatein interfaceStateStore- Parameters:
key- the state keyfactory- creates the value when absent- Returns:
- the stored value (never null)
-
clear
public void clear()- Specified by:
clearin interfaceStateStore
-
toString
-