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 Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clear all keyspaces.static KeySpaceStore
create()
Create a newKeySpaceStore
usingConcurrentHashMap
as backing map type for each keyspace map.getKeySpace
(String keyspace) Return the map associated with given keyspace.static KeySpaceStore
Create newKeySpaceStore
using given map type for each keyspace map.static KeySpaceStore
Create newKeySpaceStore
using given map as backing store.
-
Method Details
-
getKeySpace
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 togetKeySpace(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
Create a newKeySpaceStore
usingConcurrentHashMap
as backing map type for each keyspace map.- Returns:
- a new and empty
KeySpaceStore
.
-
of
Create newKeySpaceStore
using given map type for each keyspace map.- Parameters:
mapType
- map type to use.- Returns:
- the new
KeySpaceStore
object.
-
of
Create newKeySpaceStore
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 givenstore
.
-