Package net.morimekta.providence.storage
Class InMemorySetStore<K,M>
- java.lang.Object
-
- net.morimekta.providence.storage.InMemorySetStore<K,M>
-
- All Implemented Interfaces:
ReadOnlyStore<K,M>
,ReadWriteSetStore<K,M>
- Direct Known Subclasses:
InMemoryMessageSetStore
public class InMemorySetStore<K,M> extends java.lang.Object implements ReadWriteSetStore<K,M>
Simple in-memory set storage of providence messages. Uses a local hash map for storing the instances. The store is thread safe through using re-entrant read-write mutex handling, so reading can happen in parallel.
-
-
Constructor Summary
Constructors Constructor Description InMemorySetStore(java.util.function.Function<M,K> messageToKey)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
containsKey(K key)
java.util.Map<K,M>
getAll(java.util.Collection<K> keys)
Look up a set of keys from the storage.java.util.Collection<K>
keys()
Get a collection of all the keys in the store.void
putAll(java.util.Collection<M> values)
void
removeAll(java.util.Collection<K> keys)
Remove the values for the given keys.int
size()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.morimekta.providence.storage.ReadOnlyStore
get
-
Methods inherited from interface net.morimekta.providence.storage.ReadWriteSetStore
put, remove
-
-
-
-
Method Detail
-
getAll
@Nonnull public java.util.Map<K,M> getAll(@Nonnull java.util.Collection<K> keys)
Description copied from interface:ReadOnlyStore
Look up a set of keys from the storage.- Specified by:
getAll
in interfaceReadOnlyStore<K,M>
- Parameters:
keys
- The keys to look up.- Returns:
- Map of all the found key value pairs. Values not found should not have an entry in the result map (no key -> null mapping).
-
containsKey
public boolean containsKey(@Nonnull K key)
- Specified by:
containsKey
in interfaceReadOnlyStore<K,M>
- Parameters:
key
- The key to look up.- Returns:
- True if the key was contained in the map.
-
keys
@Nonnull public java.util.Collection<K> keys()
Description copied from interface:ReadOnlyStore
Get a collection of all the keys in the store.- Specified by:
keys
in interfaceReadOnlyStore<K,M>
- Returns:
- Key collection.
-
size
public int size()
- Specified by:
size
in interfaceReadOnlyStore<K,M>
- Returns:
- Get the total number of entries in the store, same as the number of unique keys.
-
putAll
public void putAll(@Nonnull java.util.Collection<M> values)
- Specified by:
putAll
in interfaceReadWriteSetStore<K,M>
- Parameters:
values
- Put all key value pairs form this map into the storage.
-
removeAll
public void removeAll(java.util.Collection<K> keys)
Description copied from interface:ReadWriteSetStore
Remove the values for the given keys.- Specified by:
removeAll
in interfaceReadWriteSetStore<K,M>
- Parameters:
keys
- Map of removed key value pairs.
-
-