Interface KeySpaceStore


public interface KeySpaceStore
Strategy interface to obtain a map for a given key space. Implementations should be thread-safe when intended for use with multiple threads (both, the store itself and the used keystore maps).

Can be used to plug in keystore creation or implementation strategies (for example, Map-based implementations such as MapDB or Infinispan) through a consolidated interface. A keyspace store represents a map of maps or a database with multiple collections and can use any kind of map per keyspace.

For example, a ConcurrentHashMap can be used as keystore map type to allow concurrent access to keyspaces using:

KeyspaceStore store = KeyspaceStore.create();
Custom map types (or instances of these) can be used as well using the provided factory methods:
KeyspaceStore store = KeyspaceStore.of(LinkedHashMap.class);

Mapinvalid input: '<'String, Mapinvalid input: '<'Object, Object>> backingMap = …;
KeyspaceStore store = KeyspaceStore.of(backingMap);
Since:
4.0
  • Method Details

    • getKeySpace

      Map<Object,Object> getKeySpace(String keyspace)
      Return the map associated with given keyspace. Implementations can return an empty map if the keyspace does not exist yet or a reference to the map that represents an existing keyspace holding keys and values for the requested keyspace.
      Parameters:
      keyspace - name of the keyspace to obtain the map for, must not be null.
      Returns:
      the map associated with the given keyspace, never null.
    • clear

      void clear()
      Clear all keyspaces. Access to getKeySpace(String) will return an empty map for each keyspace after this method call. It is not required to clear each keyspace individually but it makes sense to do so to free up memory.
    • create

      static KeySpaceStore create()
      Create a new KeySpaceStore using ConcurrentHashMap as backing map type for each keyspace map.
      Returns:
      a new and empty KeySpaceStore.
    • of

      static KeySpaceStore of(Class<? extends Map> mapType)
      Create new KeySpaceStore using given map type for each keyspace map.
      Parameters:
      mapType - map type to use.
      Returns:
      the new KeySpaceStore object.
    • of

      static KeySpaceStore of(Map<String, Map<Object,Object>> store)
      Create new KeySpaceStore using given map as backing store. Determines the map type from the given map.
      Parameters:
      store - map of maps.
      Returns:
      the new KeySpaceStore object for the given store.