Package io.pravega.client.tables.impl
Class KeyValueTableImpl<KeyT,ValueT>
- java.lang.Object
-
- io.pravega.client.tables.impl.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 forKeyValueTable.
-
-
Field Summary
-
Fields inherited from interface io.pravega.client.tables.KeyValueTable
MAXIMUM_SERIALIZED_KEY_LENGTH, MAXIMUM_SERIALIZED_VALUE_LENGTH
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes theKeyValueTable.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 theTableEntryinstances in thisKeyValueTablethat 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 thisKeyValueTableinstance as aMap.io.pravega.common.util.AsyncIterator<IteratorItem<TableKey<KeyT>>>keyIterator(@NonNull java.lang.String keyFamily, int maxKeysAtOnce, IteratorState state)Creates a new Iterator over all theTableKeys in thisKeyValueTablethat 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 theKeyValueTable.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 existingTableEntryinstances that belong to the same Key Family into thisKeyValueTable.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 asputAll(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 theKeyValueTableif 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 moreTableKeyinstances 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 theKeyValueTableif the given Key exists and its version matches the givenVersion.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 existingTableEntryinstances that belong to the same Key Family into thisKeyValueTable.
-
-
-
Method Detail
-
close
public void close()
Description copied from interface:KeyValueTableCloses theKeyValueTable. No more updates, removals, retrievals or iterators may be performed using it.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfaceKeyValueTable<KeyT,ValueT>- See Also:
AutoCloseable.close()
-
getMapFor
public KeyValueTableMap<KeyT,ValueT> getMapFor(java.lang.String keyFamily)
Description copied from interface:KeyValueTableExposes thisKeyValueTableinstance as aMap. Please refer to theKeyValueTableMapdocumentation for special cases and limitations.This is useful for integrating code that expects to deal with a
Map. Not all theKeyValueTablefunctionality can be implemented using aMap, however theMapinterface is fully implemented.- Specified by:
getMapForin interfaceKeyValueTable<KeyT,ValueT>- Parameters:
keyFamily- (Optional) The Key Family to create theKeyValueTableMapfor. Any operations on the returnedKeyValueTableMapwill only affect this Key Family. If no Key Family is provided (null), then certainKeyValueTableMapAPIs may not be supported. Refer toKeyValueTableMapdocumentation for more details.- Returns:
- A new
KeyValueTableMapinstance bound to thisKeyValueTableand Key Family.
-
put
public java.util.concurrent.CompletableFuture<Version> put(@Nullable java.lang.String keyFamily, @NonNull KeyT key, @NonNull ValueT value)
Description copied from interface:KeyValueTableUnconditionally inserts a new or updates an existing Entry in theKeyValueTable.- Specified by:
putin interfaceKeyValueTable<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
Versionassociated 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:KeyValueTableConditionally inserts a new Entry in theKeyValueTableif the given Key is not already present.- Specified by:
putIfAbsentin interfaceKeyValueTable<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
Versionassociated with the newly inserted or updated entry. Notable exceptions:ConditionalTableUpdateExceptionIf the Key is already present in theKeyValueTablefor the provided Key Family. See theKeyValueTabledoc for more details on Conditional Update Responses.
-
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:KeyValueTableUnconditionally inserts new or updates existingTableEntryinstances that belong to the same Key Family into thisKeyValueTable. All changes are performed atomically (either all or none will be accepted).- Specified by:
putAllin interfaceKeyValueTable<KeyT,ValueT>- Parameters:
keyFamily- The Key Family for the all provided Table Entries.entries- AnIterableofMap.Entryinstances to insert or update.- Returns:
- A CompletableFuture that, when completed, will contain a List of
Versioninstances 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 asputAll(String, Iterable), but accepts an iterator.- Parameters:
keyFamily- The Key Family for the all provided Table Entries.entries- AnIterableofMap.Entryinstances to insert or update.- Returns:
- A CompletableFuture that, when completed, will contain a List of
Versioninstances 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:KeyValueTableConditionally updates an existing Entry in theKeyValueTableif the given Key exists and its version matches the givenVersion.- Specified by:
replacein interfaceKeyValueTable<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- AVersionrepresenting the version that this Key must have in order to replace it.- Returns:
- A CompletableFuture that, when completed, will contain the
Versionassociated with the updated entry. Notable exceptions:ConditionalTableUpdateExceptionIf the Key is not present present in theKeyValueTablefor the provided Key Family or it is and has a differentVersion. See theKeyValueTabledoc for more details on Conditional Update Responses.
-
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:KeyValueTableInserts new or updates existingTableEntryinstances that belong to the same Key Family into thisKeyValueTable. All changes are performed atomically (either all or none will be accepted).- Specified by:
replaceAllin interfaceKeyValueTable<KeyT,ValueT>- Parameters:
keyFamily- The Key Family for the all providedTableEntryinstances.entries- AnIterableofTableEntryinstances 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 allTableEntryinstances that have one); otherwise an Unconditional Update will be performed. SeeKeyValueTabledoc for more details on Types of Updates.- Returns:
- A CompletableFuture that, when completed, will contain a List of
Versioninstances 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:ConditionalTableUpdateExceptionIf this is a Conditional Update and the condition was not satisfied. See theKeyValueTabledoc for more details on Conditional Update Responses.
-
remove
public java.util.concurrent.CompletableFuture<java.lang.Void> remove(@Nullable java.lang.String keyFamily, @NonNull KeyT key)Description copied from interface:KeyValueTableUnconditionally removes a Key from this Table Segment. If the Key does not exist, no action will be taken.- Specified by:
removein interfaceKeyValueTable<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:KeyValueTableConditionally Removes a Key from this Table Segment.- Specified by:
removein interfaceKeyValueTable<KeyT,ValueT>- Parameters:
keyFamily- (Optional) The Key Family for the Key to remove.key- The Key to remove.version- AVersionrepresenting 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:
ConditionalTableUpdateExceptionIf this is a Conditional Removal and the condition was not satisfied. See theKeyValueTabledoc for more details on Conditional Update Responses.
-
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:KeyValueTableRemoves one or moreTableKeyinstances 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:
removeAllin interfaceKeyValueTable<KeyT,ValueT>- Parameters:
keyFamily- The Key Family for theTableKey.keys- AnIterableof 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 allTableKeyinstances that have one); otherwise an Unconditional Remove will be performed. SeeKeyValueTabledoc for more details on Types of Updates.- Returns:
- A CompletableFuture that, when completed, will indicate that the keys have been removed. Notable exceptions:
ConditionalTableUpdateExceptionIf this is a Conditional Removal and the condition was not satisfied. See theKeyValueTabledoc for more details on Conditional Update Responses.
-
get
public java.util.concurrent.CompletableFuture<TableEntry<KeyT,ValueT>> get(@Nullable java.lang.String keyFamily, @NonNull KeyT key)
Description copied from interface:KeyValueTableGets the latest value for the a Key that belong to a specific Key Family.- Specified by:
getin interfaceKeyValueTable<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:KeyValueTableGets the latest values for a set of Keys that do belong to the same Key Family.- Specified by:
getAllin interfaceKeyValueTable<KeyT,ValueT>- Parameters:
keyFamily- (Optional) The Key Family for all requested Keys.keys- AnIterableof Keys to get values for.- Returns:
- A CompletableFuture that, when completed, will contain a List of
TableEntryinstances 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:KeyValueTableCreates a new Iterator over all theTableKeys in thisKeyValueTablethat belong to a specific Key Family.- Specified by:
keyIteratorin interfaceKeyValueTable<KeyT,ValueT>- Parameters:
keyFamily- The Key Family for which to iterate over keys.maxKeysAtOnce- The maximum number ofTableKeys to return with each call toAsyncIterator.getNext().state- (Optional) AnIteratorStatethat represents a continuation token that can be used to resume a previously interrupted iteration. This can be obtained by invokingIteratorItem.getState(). A null value will create an iterator that lists all keys.- Returns:
- An
AsyncIteratorthat can be used to iterate over all the Keys in thisKeyValueTablethat 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:KeyValueTableCreates a new Iterator over all theTableEntryinstances in thisKeyValueTablethat belong to a specific Key Family.- Specified by:
entryIteratorin interfaceKeyValueTable<KeyT,ValueT>- Parameters:
keyFamily- The Key Family for which to iterate over entries.maxEntriesAtOnce- The maximum number ofTableEntryinstances to return with each call toAsyncIterator.getNext().state- (Optional) AnIteratorStatethat represents a continuation token that can be used to resume a previously interrupted iteration. This can be obtained by invokingIteratorItem.getState(). A null value will create an iterator that lists all entries.- Returns:
- An
AsyncIteratorthat can be used to iterate over all the Entries in thisKeyValueTablethat belong to a specific Key Family.
-
-