Package net.morimekta.providence.storage
Class DirectoryMessageStore<K,M extends net.morimekta.providence.PMessage<M>>
- java.lang.Object
-
- net.morimekta.providence.storage.DirectoryMessageStore<K,M>
-
- Type Parameters:
K- The key type.M- The stored message type.
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,MessageReadOnlyStore<K,M>,MessageStore<K,M>,ReadOnlyStore<K,M>,ReadWriteStore<K,M>
public class DirectoryMessageStore<K,M extends net.morimekta.providence.PMessage<M>> extends java.lang.Object implements MessageStore<K,M>, java.io.Closeable
Simple file-based storage of providence messages that keeps an in-memory key index, a message cache, and stores messages to individual files in a single directly.Note that the directory store is not parallel compatible between instances, as all of them would be able to read, write etc all the files all the time.
TL;DR Each directory can only have one
DirectoryMessageStoreinstance active at a time.
-
-
Constructor Summary
Constructors Constructor Description DirectoryMessageStore(FileManager<K> manager, net.morimekta.providence.descriptor.PMessageDescriptor<M> descriptor, net.morimekta.providence.serializer.Serializer serializer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()booleancontainsKey(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.voidputAll(java.util.Map<K,M> values)voidremoveAll(java.util.Collection<K> keys)Remove the values for the given keys.intsize()-
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.MessageReadOnlyStore
getAllBuilders, getBuilder
-
Methods inherited from interface net.morimekta.providence.storage.MessageStore
putAllBuilders, putBuilder
-
Methods inherited from interface net.morimekta.providence.storage.ReadOnlyStore
get
-
Methods inherited from interface net.morimekta.providence.storage.ReadWriteStore
put, remove
-
-
-
-
Constructor Detail
-
DirectoryMessageStore
public DirectoryMessageStore(@Nonnull FileManager<K> manager, @Nonnull net.morimekta.providence.descriptor.PMessageDescriptor<M> descriptor, @Nonnull net.morimekta.providence.serializer.Serializer serializer)
-
-
Method Detail
-
containsKey
public boolean containsKey(@Nonnull K key)- Specified by:
containsKeyin interfaceReadOnlyStore<K,M extends net.morimekta.providence.PMessage<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:ReadOnlyStoreGet a collection of all the keys in the store.- Specified by:
keysin interfaceReadOnlyStore<K,M extends net.morimekta.providence.PMessage<M>>- Returns:
- Key collection.
-
size
public int size()
- Specified by:
sizein interfaceReadOnlyStore<K,M extends net.morimekta.providence.PMessage<M>>- Returns:
- Get the total number of entries in the store, same as the number of unique keys.
-
getAll
@Nonnull public java.util.Map<K,M> getAll(@Nonnull java.util.Collection<K> keys)
Description copied from interface:ReadOnlyStoreLook up a set of keys from the storage.- Specified by:
getAllin interfaceReadOnlyStore<K,M extends net.morimekta.providence.PMessage<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).
-
putAll
public void putAll(@Nonnull java.util.Map<K,M> values)- Specified by:
putAllin interfaceReadWriteStore<K,M extends net.morimekta.providence.PMessage<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:ReadWriteStoreRemove the values for the given keys.- Specified by:
removeAllin interfaceReadWriteStore<K,M extends net.morimekta.providence.PMessage<M>>- Parameters:
keys- Map of removed key value pairs.
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
-