Class DirectoryMessageListStore<K,​M extends PMessage<M,​F>,​F extends PField>

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, MessageListReadOnlyStore<K,​M,​F>, MessageListStore<K,​M,​F>, ReadOnlyStore<K,​java.util.List<M>>, ReadWriteStore<K,​java.util.List<M>>

    public class DirectoryMessageListStore<K,​M extends PMessage<M,​F>,​F extends PField>
    extends java.lang.Object
    implements MessageListStore<K,​M,​F>, java.io.Closeable
    Simple file-based storage of lists of providence messages that keeps an in-memory key index, a message cache, and stores message lists 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 DirectoryMessageListStore instance active at a time.

    • Constructor Detail

      • DirectoryMessageListStore

        public DirectoryMessageListStore​(@Nonnull
                                         java.io.File directory,
                                         @Nonnull
                                         java.util.function.Function<K,​java.lang.String> keyBuilder,
                                         @Nonnull
                                         java.util.function.Function<java.lang.String,​K> keyParser,
                                         @Nonnull
                                         PMessageDescriptor<M,​F> descriptor,
                                         @Nonnull
                                         Serializer serializer)
      • DirectoryMessageListStore

        public DirectoryMessageListStore​(@Nonnull
                                         java.nio.file.Path directory,
                                         @Nonnull
                                         java.util.function.Function<K,​java.lang.String> keyBuilder,
                                         @Nonnull
                                         java.util.function.Function<java.lang.String,​K> keyParser,
                                         @Nonnull
                                         PMessageDescriptor<M,​F> descriptor,
                                         @Nonnull
                                         Serializer serializer)
    • Method Detail

      • containsKey

        public boolean containsKey​(@Nonnull
                                   K key)
        Specified by:
        containsKey in interface ReadOnlyStore<K,​M extends PMessage<M,​F>>
        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 interface ReadOnlyStore<K,​M extends PMessage<M,​F>>
        Returns:
        Key collection.
      • size

        public int size()
        Specified by:
        size in interface ReadOnlyStore<K,​M extends PMessage<M,​F>>
        Returns:
        Get the total number of entries in the store, same as the number of unique keys.
      • getAll

        @Nonnull
        public java.util.Map<K,​java.util.List<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 interface ReadOnlyStore<K,​M extends PMessage<M,​F>>
        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

        @Nonnull
        public java.util.Map<K,​java.util.List<M>> putAll​(@Nonnull
                                                               java.util.Map<K,​java.util.List<M>> values)
        Specified by:
        putAll in interface ReadWriteStore<K,​M extends PMessage<M,​F>>
        Parameters:
        values - Put all key value pairs form this map into the storage.
        Returns:
        Immutable map of replaced values. Values not already present should not have an entry in the result map (no key -> null mapping).
      • removeAll

        @Nonnull
        public java.util.Map<K,​java.util.List<M>> removeAll​(java.util.Collection<K> keys)
        Description copied from interface: ReadWriteStore
        Remove the values for the given keys.
        Specified by:
        removeAll in interface ReadWriteStore<K,​M extends PMessage<M,​F>>
        Parameters:
        keys - Map of removed key value pairs.
        Returns:
        Immutable map of removed key value pairs. Values not removed should not have an entry in the result map (no key -> null mapping).
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable