java.lang.Object
io.agentscope.harness.agent.filesystem.remote.store.InMemoryStore
All Implemented Interfaces:
BaseStore

public class InMemoryStore extends Object implements 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 Details

    • InMemoryStore

      public InMemoryStore()
  • Method Details

    • get

      public StoreItem get(List<String> namespace, String key)
      Description copied from interface: BaseStore
      Get a single item by namespace and key.
      Specified by:
      get in interface BaseStore
      Parameters:
      namespace - hierarchical namespace path
      key - the item key within the namespace
      Returns:
      the store item, or null if not found
    • put

      public void put(List<String> namespace, String key, Map<String,Object> value)
      Description copied from interface: BaseStore
      Store or update an item.
      Specified by:
      put in interface BaseStore
      Parameters:
      namespace - hierarchical namespace path
      key - the item key within the namespace
      value - the data to store
    • 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 equals expectedVersion. An expectedVersion of 0 succeeds only when the key does not yet exist.
      Specified by:
      putIfVersion in interface BaseStore
      Parameters:
      namespace - hierarchical namespace path
      key - the item key within the namespace
      value - the new data to store
      expectedVersion - the version the caller observed; must match the current stored version
      Returns:
      true if the item was written, false if the version did not match
    • search

      public List<StoreItem> search(List<String> namespace, int limit, int offset)
      Description copied from interface: BaseStore
      Search for items within a namespace with pagination.
      Specified by:
      search in interface BaseStore
      Parameters:
      namespace - hierarchical namespace path
      limit - maximum number of items to return
      offset - number of items to skip
      Returns:
      list of matching store items
    • delete

      public void delete(List<String> namespace, String key)
      Description copied from interface: BaseStore
      Delete an item by namespace and key.
      Specified by:
      delete in interface BaseStore
      Parameters:
      namespace - hierarchical namespace path
      key - the item key to delete
    • size

      public int size()
      Returns the number of items currently stored.
    • clear

      public void clear()
      Removes all items from the store.