Delen via


ReliableHashMap<K,V> Class

  • java.lang.Object
    • microsoft.servicefabric.data.collections.ReliableCollectionsNativeAPIs
      • microsoft.servicefabric.data.collections.ReliableHashMap<K,V>

Type Parameters

K
V

public class ReliableHashMap<K extends String,V> implements ReliableCollection

Constructor Summary

Constructor Description
ReliableHashMap(long store, long replicaId, String name, String traceId)

Method Summary

Modifier and Type Method and Description
CompletableFuture<Void> clearAsync()

Removes all state from the ReliableCollection, including replicated and persisted store.

void close()
CompletableFuture<V> computeAsync(Transaction txn, K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction)

Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping).

CompletableFuture<V> computeAsync(Transaction txn, K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction, Duration timeout, CancellationToken cancellationToken)

Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping).

CompletableFuture<V> computeIfAbsentAsync(Transaction txn, K key, Function<? super K, ? extends V> mappingFunction)

If the specified key is not already associated with a value, attempts to compute its value using the given mapping function and enters it into this map unless null.

CompletableFuture<V> computeIfAbsentAsync(Transaction txn, K key, Function<? super K, ? extends V> mappingFunction, Duration timeout, CancellationToken cancellationToken)

If the specified key is not already associated with a value, attempts to compute its value using the given mapping function and enters it into this map unless null.

CompletableFuture<V> computeIfPresentAsync(Transaction txn, K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction)

If the value for the specified key is present, attempts to compute a new mapping given the key and its current mapped value.

CompletableFuture<V> computeIfPresentAsync(Transaction txn, K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction, Duration timeout, CancellationToken cancellationToken)

If the value for the specified key is present, attempts to compute a new mapping given the key and its current mapped value.

CompletableFuture<Boolean> containsKeyAsync(Transaction txn, K key)

Tests if the specified object is a key in this table.

CompletableFuture<Boolean> containsKeyAsync(Transaction txn, K key, Duration timeout, CancellationToken cancellationToken)

Tests if the specified object is a key in this table.

CompletableFuture<Boolean> containsKeyAsync(Transaction txn, K key, LockMode lockMode)

Tests if the specified object is a key in this table.

CompletableFuture<Boolean> containsKeyAsync(Transaction txn, K key, LockMode lockMode, Duration timeout, CancellationToken cancellationToken)

Tests if the specified object is a key in this table.

CompletableFuture<AsyncEnumeration<V>> elementsAsync(Transaction txn)

Returns an enumeration of the values in this table.

CompletableFuture<V> getAsync(Transaction txn, K key)

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

CompletableFuture<V> getAsync(Transaction txn, K key, Duration timeout, CancellationToken cancellationToken)

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

long getCount()

Gets the number of elements contained in the ReliableCollection

URI getName()

Gets the unique URI name for the Reliable HashMap

CompletableFuture<AsyncEnumeration<K>> keysAsync(Transaction txn)

Returns an enumeration of the keys in this table.

CompletableFuture<AsyncEnumeration<KeyValuePair<K, V>>> keyValuesAsync(Transaction txn)

Returns an enumeration of the key-value pairs in this table.

CompletableFuture<Boolean> putAsync(Transaction txn, K key, V value)

Maps the specified key to the specified value in this table. Neither the key nor the value can be null.

CompletableFuture<Boolean> putAsync(Transaction txn, K key, V value, Duration timeout, CancellationToken cancellationToken)

Maps the specified key to the specified value in this table. Neither the key nor the value can be null.

CompletableFuture<Boolean> putIfAbsentAsync(Transaction txn, K key, V value)

If the specified key is not already associated with a value, associate it with the given value.

CompletableFuture<Boolean> putIfAbsentAsync(Transaction txn, K key, V value, Duration timeout, CancellationToken cancellationToken)

If the specified key is not already associated with a value, associate it with the given value.

CompletableFuture<Boolean> removeAsync(Transaction txn, K key)

Removes the key (and its corresponding value) from this map. This method does nothing if the key is not in the map.

CompletableFuture<Boolean> removeAsync(Transaction txn, K key, Duration timeout, CancellationToken cancellationToken)

Removes the key (and its corresponding value) from this map. This method does nothing if the key is not in the map.

CompletableFuture<Boolean> replaceAsync(Transaction txn, K key, V value)

Replaces the entry for a key only if currently mapped to some value.

CompletableFuture<Boolean> replaceAsync(Transaction txn, K key, V value, Duration timeout, CancellationToken cancellationToken)

Replaces the entry for a key only if currently mapped to some value.

long size()

Returns the number of mappings.

Inherited Members

microsoft.servicefabric.data.collections.ReliableCollectionsNativeAPIs.freeTStore(long) microsoft.servicefabric.data.collections.ReliableCollectionsNativeAPIs.nativeAddAsync(long,long,String,byte [],int,long,long,int,int,CancellationToken) microsoft.servicefabric.data.collections.ReliableCollectionsNativeAPIs.nativeContainsKeyAsync(long,long,String,int,long,long,int,CancellationToken) microsoft.servicefabric.data.collections.ReliableCollectionsNativeAPIs.nativeEnumeratorAsync(long,long,long,int) microsoft.servicefabric.data.collections.ReliableCollectionsNativeAPIs.nativeGetAsync(long,long,String,long,long,int,CancellationToken) microsoft.servicefabric.data.collections.ReliableCollectionsNativeAPIs.nativeGetCount(long) microsoft.servicefabric.data.collections.ReliableCollectionsNativeAPIs.nativeKeyEnumeratorAsync(long,long,long,int) microsoft.servicefabric.data.collections.ReliableCollectionsNativeAPIs.nativePutAsync(long,long,String,byte [],int,long,long,int,int,CancellationToken) microsoft.servicefabric.data.collections.ReliableCollectionsNativeAPIs.nativePutIfAbsentAsync(long,long,String,byte [],int,long,long,int,int,CancellationToken) microsoft.servicefabric.data.collections.ReliableCollectionsNativeAPIs.nativeRemoveAsync(long,long,String,long,long,int,CancellationToken) microsoft.servicefabric.data.collections.ReliableCollectionsNativeAPIs.nativeUpdateAsync(long,long,String,byte [],int,long,long,int,int,CancellationToken)

Constructor Details

ReliableHashMap

public ReliableHashMap(long store, long replicaId, String name, String traceId)

Parameters:

store
replicaId
name
traceId

Method Details

clearAsync

public CompletableFuture clearAsync()

Removes all state from the ReliableCollection, including replicated and persisted store.

Overrides:

ReliableHashMap<K,V>.clearAsync()

Returns:

A completable future that represents the asynchronous clear operation.

close

public void close()

computeAsync

public CompletableFuture computeAsync(Transaction txn, K key, BiFunction remappingFunction)

Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping).

Parameters:

txn - The transaction id associated with this operation.
key - key with which the specified value is to be associated
remappingFunction - the function to compute a value

Returns:

CompletableFuture with the new(computed) value associated with the specified key, or null if the computed value is null. The future completes exceptionally with FabricException for fabric related failures.

Throws:

IllegalArgumentException - if key, remappingFunction or txn is null.

computeAsync

public CompletableFuture computeAsync(Transaction txn, K key, BiFunction remappingFunction, Duration timeout, CancellationToken cancellationToken)

Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping).

Parameters:

txn - The transaction id associated with this operation.
key - key with which the specified value is to be associated.
remappingFunction - the function to compute a value.
timeout - the timeout for the operation to complete. Default timeout(4 seconds) will be used if null is passed.
cancellationToken -

CancellationToken object to indicate the cancellation status of the operation.

Returns:

CompletableFuture with the new(computed) value associated with the specified key, or null if the computed value is null. The future completes exceptionally with FabricException for fabric related failures.

Throws:

IllegalArgumentException - if key, remappingFunction or txn is null.

computeIfAbsentAsync

public CompletableFuture computeIfAbsentAsync(Transaction txn, K key, Function mappingFunction)

If the specified key is not already associated with a value, attempts to compute its value using the given mapping function and enters it into this map unless null.

Parameters:

txn - The transaction id associated with this operation.
key - key with which the specified value is to be associated
mappingFunction - the function to compute a value

Returns:

CompletableFuture with the new(computed) value if there was no previous mapping, or null if the computed value is null or if a mapping already exists for the specified key. The future completes exceptionally with FabricException for fabric related failures.

Throws:

IllegalArgumentException - if key, mappingFunction or txn is null.

computeIfAbsentAsync

public CompletableFuture computeIfAbsentAsync(Transaction txn, K key, Function mappingFunction, Duration timeout, CancellationToken cancellationToken)

If the specified key is not already associated with a value, attempts to compute its value using the given mapping function and enters it into this map unless null.

Parameters:

txn - The transaction id associated with this operation.
key - key with which the specified value is to be associated
mappingFunction - the function to compute a value
timeout - the timeout for the operation to complete. Default timeout(4 seconds) will be used if null is passed.
cancellationToken -

CancellationToken object to indicate the cancellation status of the operation.

Returns:

CompletableFuture with the new(computed) value if there was no previous mapping, or null if the computed value is null or if a mapping already exists for the specified key. The future completes exceptionally with FabricException for fabric related failures.

Throws:

IllegalArgumentException - if key, mappingFunction or txn is null.

computeIfPresentAsync

public CompletableFuture computeIfPresentAsync(Transaction txn, K key, BiFunction remappingFunction)

If the value for the specified key is present, attempts to compute a new mapping given the key and its current mapped value.

Parameters:

txn - The transaction id associated with this operation.
key - key with which a value may be associated.
remappingFunction - the function to compute a value.

Returns:

CompletableFuture with the new(computed) value if there was a previous mapping, or null if the computed value is null or if no mapping exists for the specified key. The future completes exceptionally with FabricException for fabric related failures.

Throws:

IllegalArgumentException - if key, remappingFunction or txn is null.

computeIfPresentAsync

public CompletableFuture computeIfPresentAsync(Transaction txn, K key, BiFunction remappingFunction, Duration timeout, CancellationToken cancellationToken)

If the value for the specified key is present, attempts to compute a new mapping given the key and its current mapped value.

Parameters:

txn - The transaction id associated with this operation.
key - key with which a value may be associated.
remappingFunction - the function to compute a value.
timeout - the timeout for the operation to complete. Default timeout(4 seconds) will be used if null is passed.
cancellationToken -

CancellationToken object to indicate the cancellation status of the operation.

Returns:

CompletableFuture with the new(computed) value if there was a previous mapping, or null if the computed value is null or if no mapping exists for the specified key. The future completes exceptionally with FabricException for fabric related failures.

Throws:

IllegalArgumentException - if key, remappingFunction or txn is null.

containsKeyAsync

public CompletableFuture containsKeyAsync(Transaction txn, K key)

Tests if the specified object is a key in this table.

Parameters:

txn - The transaction id associated with this operation.
key - possible key

Returns:

CompletableFuture with result true if the key is found in this Map, false otherwise. The future completes exceptionally with FabricException for fabric related failures.

Throws:

IllegalArgumentException - if key or txn is null.

containsKeyAsync

public CompletableFuture containsKeyAsync(Transaction txn, K key, Duration timeout, CancellationToken cancellationToken)

Tests if the specified object is a key in this table.

Parameters:

txn - The transaction id associated with this operation.
key - possible key
timeout - the timeout for the operation to complete. Default timeout(4 seconds) will be used if null is passed.
cancellationToken -

CancellationToken object to indicate the cancellation status of the operation.

Returns:

CompletableFuture with result true if the key is found in this Map, false otherwise. The future completes exceptionally with FabricException for fabric related failures.

Throws:

IllegalArgumentException - if key or txn is null.

containsKeyAsync

public CompletableFuture containsKeyAsync(Transaction txn, K key, LockMode lockMode)

Tests if the specified object is a key in this table.

Parameters:

txn - The transaction id associated with this operation.
key - possible key
lockMode - The lock mode to obtain while checking for presence of the key.

Returns:

CompletableFuture with result true if the key is found in this Map, false otherwise. The future completes exceptionally with FabricException for fabric related failures.

Throws:

IllegalArgumentException - if key or txn is null.

containsKeyAsync

public CompletableFuture containsKeyAsync(Transaction txn, K key, LockMode lockMode, Duration timeout, CancellationToken cancellationToken)

Tests if the specified object is a key in this table.

Parameters:

txn - The transaction id associated with this operation.
key - possible key
lockMode - The lock mode to obtain while checking for presence of the key.
timeout - the timeout for the operation to complete. Default timeout(4 seconds) will be used if null is passed.
cancellationToken -

CancellationToken object to indicate the cancellation status of the operation.

Returns:

CompletableFuture with result true if the key is found in this Map, false otherwise. The future completes exceptionally with FabricException for fabric related failures.

Throws:

IllegalArgumentException - if key or txn is null.

elementsAsync

public CompletableFuture> elementsAsync(Transaction txn)

Returns an enumeration of the values in this table.

Parameters:

txn - The transaction id associated with this operation.

Returns:

CompletableFuture with an enumeration of the values in this Map. The future completes exceptionally with FabricException for fabric related failures.

Throws:

IllegalArgumentException - if txn is null.

getAsync

public CompletableFuture getAsync(Transaction txn, K key)

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Parameters:

txn - The transaction id associated with this operation.
key - the key whose associated value is to be returned

Returns:

CompletableFuture with value to which the specified key is mapped, null if no such mapping exists. The future completes exceptionally with IOException or ClassNotFoundException for deserialization failures, FabricException for fabric related failures.

Throws:

IllegalArgumentException - if key or txn is null.

getAsync

public CompletableFuture getAsync(Transaction txn, K key, Duration timeout, CancellationToken cancellationToken)

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Parameters:

txn - The transaction id associated with this operation.
key - the key whose associated value is to be returned
timeout - the timeout for the operation to complete. Default timeout(4 seconds) will be used if null is passed.
cancellationToken -

CancellationToken object to indicate the cancellation status of the operation.

Returns:

CompletableFuture with value to which the specified key is mapped, null if no such mapping exists. The future completes exceptionally with IOException or ClassNotFoundException for deserialization failures, FabricException for fabric related failures.

Throws:

IllegalArgumentException - if key or txn is null.

getCount

public long getCount()

Gets the number of elements contained in the ReliableCollection

Overrides:

ReliableHashMap<K,V>.getCount()

Returns:

The number of elements.

getName

public URI getName()

Gets the unique URI name for the Reliable HashMap

Overrides:

ReliableHashMap<K,V>.getName()

keysAsync

public CompletableFuture> keysAsync(Transaction txn)

Returns an enumeration of the keys in this table.

Parameters:

txn - The transaction id associated with this operation.

Returns:

CompletableFuture with an enumeration of the keys in this Map. The future completes exceptionally with FabricException for fabric related failures.

Throws:

IllegalArgumentException - if txn is null.

keyValuesAsync

public CompletableFuture>> keyValuesAsync(Transaction txn)

Returns an enumeration of the key-value pairs in this table.

Parameters:

txn - The transaction id associated with this operation.

Returns:

CompletableFuture with an enumeration of KeyValuePair in this Map. The future completes exceptionally with FabricException for fabric related failures.

Throws:

IllegalArgumentException - if txn is null.

putAsync

public CompletableFuture putAsync(Transaction txn, K key, V value)

Maps the specified key to the specified value in this table. Neither the key nor the value can be null.

Parameters:

txn - The transaction id associated with this operation.
key - key with which the specified value is to be associated
value - value to be associated with the specified key

Returns:

CompletableFuture with result true if there was a previous mapping, false otherwise. The future completes exceptionally with IOException for serialization failures, FabricException for fabric related failures.

Throws:

IllegalArgumentException - if key, value or txn is null.

putAsync

public CompletableFuture putAsync(Transaction txn, K key, V value, Duration timeout, CancellationToken cancellationToken)

Maps the specified key to the specified value in this table. Neither the key nor the value can be null.

Parameters:

txn - The transaction id associated with this operation.
key - key with which the specified value is to be associated
value - value to be associated with the specified key
timeout - the timeout for the operation to complete. Default timeout(4 seconds) will be used if null is passed.
cancellationToken -

CancellationToken object to indicate the cancellation status of the operation.

Returns:

CompletableFuture with result true if there was a previous mapping, false otherwise. The future completes exceptionally with IOException for serialization failures, FabricException for fabric related failures.

Throws:

IllegalArgumentException - if key, value or txn is null.

putIfAbsentAsync

public CompletableFuture putIfAbsentAsync(Transaction txn, K key, V value)

If the specified key is not already associated with a value, associate it with the given value.

Parameters:

txn - The transaction id associated with this operation.
key - key with which the specified value is to be associated
value - value to be associated with the specified key

Returns:

CompletableFuture with result true if the value is applied, false otherwise. The future completes exceptionally with IOException for serialization failures, FabricException for fabric related failures.

Throws:

IllegalArgumentException - if key, value or txn is null.

putIfAbsentAsync

public CompletableFuture putIfAbsentAsync(Transaction txn, K key, V value, Duration timeout, CancellationToken cancellationToken)

If the specified key is not already associated with a value, associate it with the given value.

Parameters:

txn - The transaction id associated with this operation.
key - key with which the specified value is to be associated
value - value to be associated with the specified key
timeout - the timeout for the operation to complete. Default timeout(4 seconds) will be used if null is passed.
cancellationToken -

CancellationToken object to indicate the cancellation status of the operation.

Returns:

CompletableFuture with result true if the value is applied, false otherwise. The future completes exceptionally with IOException for serialization failures, FabricException for fabric related failures.

Throws:

IllegalArgumentException - if key, value or txn is null.

removeAsync

public CompletableFuture removeAsync(Transaction txn, K key)

Removes the key (and its corresponding value) from this map. This method does nothing if the key is not in the map.

Parameters:

txn - The transaction id associated with this operation.
key - the key that needs to be removed.

Returns:

CompletableFuture with result true if the key is found and remove succeeds, false otherwise. The future completes exceptionally with FabricException for fabric related failures.

Throws:

IllegalArgumentException - if key or txn is null.

removeAsync

public CompletableFuture removeAsync(Transaction txn, K key, Duration timeout, CancellationToken cancellationToken)

Removes the key (and its corresponding value) from this map. This method does nothing if the key is not in the map.

Parameters:

txn - The transaction id associated with this operation.
key - the key that needs to be removed.
timeout - the timeout for the operation to complete. Default timeout(4 seconds) will be used if null is passed.
cancellationToken -

CancellationToken object to indicate the cancellation status of the operation.

Returns:

CompletableFuture with result true if the key is found and remove succeeds, false otherwise. The future completes exceptionally with FabricException for fabric related failures.

Throws:

IllegalArgumentException - if key or txn is null.

replaceAsync

public CompletableFuture replaceAsync(Transaction txn, K key, V value)

Replaces the entry for a key only if currently mapped to some value.

Parameters:

txn - The transaction id associated with this operation.
key - key with which the specified value is associated
value - value to be associated with the specified key

Returns:

CompletableFuture with result true if the key is found and replace succeeds, false otherwise. The future completes exceptionally with IOException for serialization failures, FabricException for fabric related failures.

Throws:

IllegalArgumentException - if key, value or txn is null.

replaceAsync

public CompletableFuture replaceAsync(Transaction txn, K key, V value, Duration timeout, CancellationToken cancellationToken)

Replaces the entry for a key only if currently mapped to some value.

Parameters:

txn - The transaction id associated with this operation.
key - key with which the specified value is associated
value - value to be associated with the specified key
timeout - the timeout for the operation to complete. Default timeout(4 seconds) will be used if null is passed.
cancellationToken -

CancellationToken object to indicate the cancellation status of the operation.

Returns:

CompletableFuture with result true if the key is found and replace succeeds, false otherwise. The future completes exceptionally with IOException for serialization failures, FabricException for fabric related failures.

Throws:

IllegalArgumentException - if key, value or txn is null.

size

public long size()

Returns the number of mappings.

Returns:

This method returns the number of mappings in the map. This is not a asynchronous call. It gives BEST EFFORT number of mappings.

Applies to