Class InMemoryStore
java.lang.Object
io.agentscope.harness.agent.filesystem.remote.store.InMemoryStore
- All Implemented Interfaces:
BaseStore
Thread-safe in-memory implementation of
BaseStore.
Items are stored in a ConcurrentHashMap keyed by the concatenation of
namespace components and the item key, separated by '\0'.
Every successful put(java.util.List<java.lang.String>, java.lang.String, java.util.Map<java.lang.String, java.lang.Object>) and putIfVersion(java.util.List<java.lang.String>, java.lang.String, java.util.Map<java.lang.String, java.lang.Object>, long) increments the item's
StoreItem.version() counter, enabling optimistic concurrency control.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all items from the store.voidDelete an item by namespace and key.Get a single item by namespace and key.voidStore or update an item.booleanAtomic compare-and-swap: updates the item only when the stored version equalsexpectedVersion.Search for items within a namespace with pagination.intsize()Returns the number of items currently stored.
-
Constructor Details
-
InMemoryStore
public InMemoryStore()
-
-
Method Details
-
get
Description copied from interface:BaseStoreGet a single item by namespace and key. -
put
Description copied from interface:BaseStoreStore or update an item. -
putIfVersion
public boolean putIfVersion(List<String> namespace, String key, Map<String, Object> value, long expectedVersion) Atomic compare-and-swap: updates the item only when the stored version equalsexpectedVersion. AnexpectedVersionof0succeeds only when the key does not yet exist.- Specified by:
putIfVersionin interfaceBaseStore- Parameters:
namespace- hierarchical namespace pathkey- the item key within the namespacevalue- the new data to storeexpectedVersion- the version the caller observed; must match the current stored version- Returns:
trueif the item was written,falseif the version did not match
-
search
Description copied from interface:BaseStoreSearch for items within a namespace with pagination. -
delete
Description copied from interface:BaseStoreDelete an item by namespace and key. -
size
public int size()Returns the number of items currently stored. -
clear
public void clear()Removes all items from the store.
-