Class KeyValueTableImpl<KeyT,​ValueT>

  • Type Parameters:
    KeyT - Type for Key.
    ValueT - Type for Value.
    All Implemented Interfaces:
    KeyValueTable<KeyT,​ValueT>, java.lang.AutoCloseable

    public class KeyValueTableImpl<KeyT,​ValueT>
    extends java.lang.Object
    implements KeyValueTable<KeyT,​ValueT>, java.lang.AutoCloseable
    Implementation for KeyValueTable.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the KeyValueTable.
      io.pravega.common.util.AsyncIterator<IteratorItem<TableEntry<KeyT,​ValueT>>> entryIterator​(@NonNull java.lang.String keyFamily, int maxEntriesAtOnce, IteratorState state)
      Creates a new Iterator over all the TableEntry instances in this KeyValueTable that belong to a specific Key Family.
      java.util.concurrent.CompletableFuture<TableEntry<KeyT,​ValueT>> get​(java.lang.String keyFamily, KeyT key)
      Gets the latest value for the a Key that belong to a specific Key Family.
      java.util.concurrent.CompletableFuture<java.util.List<TableEntry<KeyT,​ValueT>>> getAll​(java.lang.String keyFamily, @NonNull java.lang.Iterable<KeyT> keys)
      Gets the latest values for a set of Keys that do belong to the same Key Family.
      KeyValueTableMap<KeyT,​ValueT> getMapFor​(java.lang.String keyFamily)
      Exposes this KeyValueTable instance as a Map.
      io.pravega.common.util.AsyncIterator<IteratorItem<TableKey<KeyT>>> keyIterator​(@NonNull java.lang.String keyFamily, int maxKeysAtOnce, IteratorState state)
      Creates a new Iterator over all the TableKeys in this KeyValueTable that belong to a specific Key Family.
      java.util.concurrent.CompletableFuture<Version> put​(java.lang.String keyFamily, KeyT key, ValueT value)
      Unconditionally inserts a new or updates an existing Entry in the KeyValueTable.
      java.util.concurrent.CompletableFuture<java.util.List<Version>> putAll​(@NonNull java.lang.String keyFamily, @NonNull java.lang.Iterable<java.util.Map.Entry<KeyT,​ValueT>> entries)
      Unconditionally inserts new or updates existing TableEntry instances that belong to the same Key Family into this KeyValueTable.
      java.util.concurrent.CompletableFuture<java.util.List<Version>> putAll​(@NonNull java.lang.String keyFamily, @NonNull java.util.Iterator<java.util.Map.Entry<KeyT,​ValueT>> entries)
      Same as putAll(String, Iterable), but accepts an iterator.
      java.util.concurrent.CompletableFuture<Version> putIfAbsent​(java.lang.String keyFamily, KeyT key, ValueT value)
      Conditionally inserts a new Entry in the KeyValueTable if the given Key is not already present.
      java.util.concurrent.CompletableFuture<java.lang.Void> remove​(java.lang.String keyFamily, KeyT key)
      Unconditionally removes a Key from this Table Segment.
      java.util.concurrent.CompletableFuture<java.lang.Void> remove​(java.lang.String keyFamily, KeyT key, @NonNull Version version)
      Conditionally Removes a Key from this Table Segment.
      java.util.concurrent.CompletableFuture<java.lang.Void> removeAll​(@NonNull java.lang.String keyFamily, @NonNull java.lang.Iterable<TableKey<KeyT>> keys)
      Removes one or more TableKey instances that belong to the same Key Family from this Table Segment.
      java.util.concurrent.CompletableFuture<Version> replace​(java.lang.String keyFamily, KeyT key, ValueT value, @NonNull Version version)
      Conditionally updates an existing Entry in the KeyValueTable if the given Key exists and its version matches the given Version.
      java.util.concurrent.CompletableFuture<java.util.List<Version>> replaceAll​(@NonNull java.lang.String keyFamily, @NonNull java.lang.Iterable<TableEntry<KeyT,​ValueT>> entries)
      Inserts new or updates existing TableEntry instances that belong to the same Key Family into this KeyValueTable.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • close

        public void close()
        Description copied from interface: KeyValueTable
        Closes the KeyValueTable. No more updates, removals, retrievals or iterators may be performed using it.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface KeyValueTable<KeyT,​ValueT>
        See Also:
        AutoCloseable.close()
      • put

        public java.util.concurrent.CompletableFuture<Version> put​(@Nullable
                                                                   java.lang.String keyFamily,
                                                                   @NonNull
                                                                   KeyT key,
                                                                   @NonNull
                                                                   ValueT value)
        Description copied from interface: KeyValueTable
        Unconditionally inserts a new or updates an existing Entry in the KeyValueTable.
        Specified by:
        put in interface KeyValueTable<KeyT,​ValueT>
        Parameters:
        keyFamily - (Optional) The Key Family for the Entry. If null, this Entry will not be associated with any Key Family.
        key - The Key to insert or update.
        value - The Value to be associated with the Key.
        Returns:
        A CompletableFuture that, when completed, will contain the Version associated with the newly inserted or updated entry.
      • putIfAbsent

        public java.util.concurrent.CompletableFuture<Version> putIfAbsent​(@Nullable
                                                                           java.lang.String keyFamily,
                                                                           @NonNull
                                                                           KeyT key,
                                                                           @NonNull
                                                                           ValueT value)
        Description copied from interface: KeyValueTable
        Conditionally inserts a new Entry in the KeyValueTable if the given Key is not already present.
        Specified by:
        putIfAbsent in interface KeyValueTable<KeyT,​ValueT>
        Parameters:
        keyFamily - (Optional) The Key Family for the Entry. If null, this Entry will not be associated with any Key Family.
        key - The Key to insert.
        value - The Value to be associated with the Key.
        Returns:
        A CompletableFuture that, when completed, will contain the Version associated with the newly inserted or updated entry. Notable exceptions:
      • putAll

        public java.util.concurrent.CompletableFuture<java.util.List<Version>> putAll​(@NonNull
                                                                                      @NonNull java.lang.String keyFamily,
                                                                                      @NonNull
                                                                                      @NonNull java.lang.Iterable<java.util.Map.Entry<KeyT,​ValueT>> entries)
        Description copied from interface: KeyValueTable
        Unconditionally inserts new or updates existing TableEntry instances that belong to the same Key Family into this KeyValueTable. All changes are performed atomically (either all or none will be accepted).
        Specified by:
        putAll in interface KeyValueTable<KeyT,​ValueT>
        Parameters:
        keyFamily - The Key Family for the all provided Table Entries.
        entries - An Iterable of Map.Entry instances to insert or update.
        Returns:
        A CompletableFuture that, when completed, will contain a List of Version instances which represent the versions for the inserted/updated keys. The size of this list will be the same as the number of items in entries and the versions will be in the same order as the entries.
      • putAll

        public java.util.concurrent.CompletableFuture<java.util.List<Version>> putAll​(@NonNull
                                                                                      @NonNull java.lang.String keyFamily,
                                                                                      @NonNull
                                                                                      @NonNull java.util.Iterator<java.util.Map.Entry<KeyT,​ValueT>> entries)
        Same as putAll(String, Iterable), but accepts an iterator.
        Parameters:
        keyFamily - The Key Family for the all provided Table Entries.
        entries - An Iterable of Map.Entry instances to insert or update.
        Returns:
        A CompletableFuture that, when completed, will contain a List of Version instances which represent the versions for the inserted/updated keys. The size of this list will be the same as the number of items in entries and the versions will be in the same order as the entries.
      • replace

        public java.util.concurrent.CompletableFuture<Version> replace​(@Nullable
                                                                       java.lang.String keyFamily,
                                                                       @NonNull
                                                                       KeyT key,
                                                                       @NonNull
                                                                       ValueT value,
                                                                       @NonNull
                                                                       @NonNull Version version)
        Description copied from interface: KeyValueTable
        Conditionally updates an existing Entry in the KeyValueTable if the given Key exists and its version matches the given Version.
        Specified by:
        replace in interface KeyValueTable<KeyT,​ValueT>
        Parameters:
        keyFamily - (Optional) The Key Family for the Entry. If null, this Entry will not be associated with any Key Family.
        key - The Key to update.
        value - The new Value to be associated with the Key.
        version - A Version representing the version that this Key must have in order to replace it.
        Returns:
        A CompletableFuture that, when completed, will contain the Version associated with the updated entry. Notable exceptions:
      • replaceAll

        public java.util.concurrent.CompletableFuture<java.util.List<Version>> replaceAll​(@NonNull
                                                                                          @NonNull java.lang.String keyFamily,
                                                                                          @NonNull
                                                                                          @NonNull java.lang.Iterable<TableEntry<KeyT,​ValueT>> entries)
        Description copied from interface: KeyValueTable
        Inserts new or updates existing TableEntry instances that belong to the same Key Family into this KeyValueTable. All changes are performed atomically (either all or none will be accepted).
        Specified by:
        replaceAll in interface KeyValueTable<KeyT,​ValueT>
        Parameters:
        keyFamily - The Key Family for the all provided TableEntry instances.
        entries - An Iterable of TableEntry instances to insert or update. If for at least one such entry, TableEntry.getKey()TableKey.getVersion() indicates a conditional update, this will perform an atomic Conditional Update conditioned on the server-side versions matching the provided ones (for all TableEntry instances that have one); otherwise an Unconditional Update will be performed. See KeyValueTable doc for more details on Types of Updates.
        Returns:
        A CompletableFuture that, when completed, will contain a List of Version instances which represent the versions for the inserted/updated keys. The size of this list will be the same as entries.size() and the versions will be in the same order as the entries. Notable exceptions:
      • remove

        public java.util.concurrent.CompletableFuture<java.lang.Void> remove​(@Nullable
                                                                             java.lang.String keyFamily,
                                                                             @NonNull
                                                                             KeyT key)
        Description copied from interface: KeyValueTable
        Unconditionally removes a Key from this Table Segment. If the Key does not exist, no action will be taken.
        Specified by:
        remove in interface KeyValueTable<KeyT,​ValueT>
        Parameters:
        keyFamily - (Optional) The Key Family for the Key to remove.
        key - The Key to remove.
        Returns:
        A CompletableFuture that, when completed, will indicate the Key has been removed.
      • remove

        public java.util.concurrent.CompletableFuture<java.lang.Void> remove​(@Nullable
                                                                             java.lang.String keyFamily,
                                                                             @NonNull
                                                                             KeyT key,
                                                                             @NonNull
                                                                             @NonNull Version version)
        Description copied from interface: KeyValueTable
        Conditionally Removes a Key from this Table Segment.
        Specified by:
        remove in interface KeyValueTable<KeyT,​ValueT>
        Parameters:
        keyFamily - (Optional) The Key Family for the Key to remove.
        key - The Key to remove.
        version - A Version representing the version that this Key must have in order to remove it.
        Returns:
        A CompletableFuture that, when completed, will indicate the Key has been removed. Notable exceptions:
      • removeAll

        public java.util.concurrent.CompletableFuture<java.lang.Void> removeAll​(@NonNull
                                                                                @NonNull java.lang.String keyFamily,
                                                                                @NonNull
                                                                                @NonNull java.lang.Iterable<TableKey<KeyT>> keys)
        Description copied from interface: KeyValueTable
        Removes one or more TableKey instances that belong to the same Key Family from this Table Segment. All removals are performed atomically (either all keys or no key will be removed).
        Specified by:
        removeAll in interface KeyValueTable<KeyT,​ValueT>
        Parameters:
        keyFamily - The Key Family for the TableKey.
        keys - An Iterable of keys to remove. If for at least one such key, TableKey.getVersion() indicates a conditional update, this will perform an atomic Conditional Remove conditioned on the server-side versions matching the provided ones (for all TableKey instances that have one); otherwise an Unconditional Remove will be performed. See KeyValueTable doc for more details on Types of Updates.
        Returns:
        A CompletableFuture that, when completed, will indicate that the keys have been removed. Notable exceptions:
      • get

        public java.util.concurrent.CompletableFuture<TableEntry<KeyT,​ValueT>> get​(@Nullable
                                                                                         java.lang.String keyFamily,
                                                                                         @NonNull
                                                                                         KeyT key)
        Description copied from interface: KeyValueTable
        Gets the latest value for the a Key that belong to a specific Key Family.
        Specified by:
        get in interface KeyValueTable<KeyT,​ValueT>
        Parameters:
        keyFamily - (Optional) The Key Family for the Key to get.
        key - The Key to get the value for.
        Returns:
        A CompletableFuture that, when completed, will contain the requested result. If no such Key exists, this will be completed with a null value.
      • getAll

        public java.util.concurrent.CompletableFuture<java.util.List<TableEntry<KeyT,​ValueT>>> getAll​(@Nullable
                                                                                                            java.lang.String keyFamily,
                                                                                                            @NonNull
                                                                                                            @NonNull java.lang.Iterable<KeyT> keys)
        Description copied from interface: KeyValueTable
        Gets the latest values for a set of Keys that do belong to the same Key Family.
        Specified by:
        getAll in interface KeyValueTable<KeyT,​ValueT>
        Parameters:
        keyFamily - (Optional) The Key Family for all requested Keys.
        keys - An Iterable of Keys to get values for.
        Returns:
        A CompletableFuture that, when completed, will contain a List of TableEntry instances for the requested keys. The size of the list will be the same as keys.size() and the results will be in the same order as the requested keys. Any keys which do not have a value will have a null entry at their index.
      • keyIterator

        public io.pravega.common.util.AsyncIterator<IteratorItem<TableKey<KeyT>>> keyIterator​(@NonNull
                                                                                              @NonNull java.lang.String keyFamily,
                                                                                              int maxKeysAtOnce,
                                                                                              @Nullable
                                                                                              IteratorState state)
        Description copied from interface: KeyValueTable
        Creates a new Iterator over all the TableKeys in this KeyValueTable that belong to a specific Key Family.
        Specified by:
        keyIterator in interface KeyValueTable<KeyT,​ValueT>
        Parameters:
        keyFamily - The Key Family for which to iterate over keys.
        maxKeysAtOnce - The maximum number of TableKeys to return with each call to AsyncIterator.getNext().
        state - (Optional) An IteratorState that represents a continuation token that can be used to resume a previously interrupted iteration. This can be obtained by invoking IteratorItem.getState(). A null value will create an iterator that lists all keys.
        Returns:
        An AsyncIterator that can be used to iterate over all the Keys in this KeyValueTable that belong to a specific Key Family.
      • entryIterator

        public io.pravega.common.util.AsyncIterator<IteratorItem<TableEntry<KeyT,​ValueT>>> entryIterator​(@NonNull
                                                                                                               @NonNull java.lang.String keyFamily,
                                                                                                               int maxEntriesAtOnce,
                                                                                                               @Nullable
                                                                                                               IteratorState state)
        Description copied from interface: KeyValueTable
        Creates a new Iterator over all the TableEntry instances in this KeyValueTable that belong to a specific Key Family.
        Specified by:
        entryIterator in interface KeyValueTable<KeyT,​ValueT>
        Parameters:
        keyFamily - The Key Family for which to iterate over entries.
        maxEntriesAtOnce - The maximum number of TableEntry instances to return with each call to AsyncIterator.getNext().
        state - (Optional) An IteratorState that represents a continuation token that can be used to resume a previously interrupted iteration. This can be obtained by invoking IteratorItem.getState(). A null value will create an iterator that lists all entries.
        Returns:
        An AsyncIterator that can be used to iterate over all the Entries in this KeyValueTable that belong to a specific Key Family.