Class AbstractMemoryDataStore<V extends java.io.Serializable>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) java.util.HashMap<java.lang.String,​byte[]> keyValueMap
      Data store map from the key to the value.
      private java.util.concurrent.locks.Lock lock
      Lock on access to the store.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      DataStore<V> clear()
      Deletes all of the stored keys and values.
      boolean containsKey​(java.lang.String key)
      Returns whether the store contains the given key.
      boolean containsValue​(V value)
      Returns whether the store contains the given value.
      DataStore<V> delete​(java.lang.String key)
      Deletes the stored key and value based on the given key, or ignored if the key doesn't already exist.
      V get​(java.lang.String key)
      Returns the stored value for the given key or null if not found.
      boolean isEmpty()
      Returns whether there are any stored keys.
      java.util.Set<java.lang.String> keySet()
      Returns the unmodifiable set of all stored keys.
      (package private) void save()
      Persist the key-value map into storage at the end of set(java.lang.String, V), delete(String), and clear().
      DataStore<V> set​(java.lang.String key, V value)
      Stores the given value for the given key (replacing any existing value).
      int size()
      Returns the number of stored keys.
      java.lang.String toString()  
      java.util.Collection<V> values()
      Returns the unmodifiable collection of all stored values.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • lock

        private final java.util.concurrent.locks.Lock lock
        Lock on access to the store.
      • keyValueMap

        java.util.HashMap<java.lang.String,​byte[]> keyValueMap
        Data store map from the key to the value.
    • Constructor Detail

      • AbstractMemoryDataStore

        protected AbstractMemoryDataStore​(DataStoreFactory dataStoreFactory,
                                          java.lang.String id)
        Parameters:
        dataStoreFactory - data store factory
        id - data store ID
    • Method Detail

      • keySet

        public final java.util.Set<java.lang.String> keySet()
                                                     throws java.io.IOException
        Description copied from interface: DataStore
        Returns the unmodifiable set of all stored keys.

        Order of the keys is not specified.

        Throws:
        java.io.IOException
      • values

        public final java.util.Collection<V> values()
                                             throws java.io.IOException
        Description copied from interface: DataStore
        Returns the unmodifiable collection of all stored values.
        Throws:
        java.io.IOException
      • get

        public final V get​(java.lang.String key)
                    throws java.io.IOException
        Description copied from interface: DataStore
        Returns the stored value for the given key or null if not found.
        Parameters:
        key - key or null for null result
        Throws:
        java.io.IOException
      • set

        public final DataStore<V> set​(java.lang.String key,
                                      V value)
                               throws java.io.IOException
        Description copied from interface: DataStore
        Stores the given value for the given key (replacing any existing value).
        Parameters:
        key - key
        value - value object
        Throws:
        java.io.IOException
      • delete

        public DataStore<V> delete​(java.lang.String key)
                            throws java.io.IOException
        Description copied from interface: DataStore
        Deletes the stored key and value based on the given key, or ignored if the key doesn't already exist.
        Parameters:
        key - key or null to ignore
        Throws:
        java.io.IOException
      • clear

        public final DataStore<V> clear()
                                 throws java.io.IOException
        Description copied from interface: DataStore
        Deletes all of the stored keys and values.
        Throws:
        java.io.IOException
      • containsKey

        public boolean containsKey​(java.lang.String key)
                            throws java.io.IOException
        Description copied from class: AbstractDataStore
        Returns whether the store contains the given key.

        Default implementation is to call DataStore.get(String) and check if it is null.

        Specified by:
        containsKey in interface DataStore<V extends java.io.Serializable>
        Overrides:
        containsKey in class AbstractDataStore<V extends java.io.Serializable>
        Throws:
        java.io.IOException
      • containsValue

        public boolean containsValue​(V value)
                              throws java.io.IOException
        Description copied from class: AbstractDataStore
        Returns whether the store contains the given value.

        Default implementation is to call Collection.contains(Object) on DataStore.values().

        Specified by:
        containsValue in interface DataStore<V extends java.io.Serializable>
        Overrides:
        containsValue in class AbstractDataStore<V extends java.io.Serializable>
        Throws:
        java.io.IOException
      • size

        public int size()
                 throws java.io.IOException
        Description copied from class: AbstractDataStore
        Returns the number of stored keys.

        Default implementation is to call Set.size() on DataStore.keySet().

        Specified by:
        size in interface DataStore<V extends java.io.Serializable>
        Overrides:
        size in class AbstractDataStore<V extends java.io.Serializable>
        Throws:
        java.io.IOException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object