Interface FunctionalMap.ReadWriteMap<K,V>
- All Superinterfaces:
AutoCloseable,FunctionalMap<K,V>
- All Known Implementing Classes:
ReadWriteMapImpl
- Enclosing interface:
- FunctionalMap<K,
V>
EntryView.ReadWriteEntryView.
Read-write operations offer the possibility of writing values or metadata parameters, and returning previously stored information. Read-write operations are also crucial for implementing conditional, compare-and-swap (CAS) like operations.
Locks are acquired before executing the read-write lambda.
Method parameters for read-write operations, including lambdas, must be marshallable when running in a cluster.
- Since:
- 8.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.infinispan.functional.FunctionalMap
FunctionalMap.ReadOnlyMap<K,V>, FunctionalMap.ReadWriteMap<K, V>, FunctionalMap.WriteOnlyMap<K, V> -
Method Summary
Modifier and TypeMethodDescription<R> CompletableFuture<R>Evaluate a read-write function on the value and metadata associated with the key and return aCompletableFuturewith the return type of the function.default <R> CompletableFuture<R>eval(K key, SerializableFunction<EntryView.ReadWriteEntryView<K, V>, R> f) Same aseval(Object, Function)except that the function must also implementSerializable<T,R> CompletableFuture<R> eval(K key, T argument, BiFunction<T, EntryView.ReadWriteEntryView<K, V>, R> f) Evaluate a read-write function, with an argument passed in and aEntryView.WriteEntryViewof the value associated with the key, and return aCompletableFuturewhich will be completed with the returned value by the function.default <T,R> CompletableFuture<R> eval(K key, T argument, SerializableBiFunction<T, EntryView.ReadWriteEntryView<K, V>, R> f) Same aseval(Object, Object, BiFunction)except that the function must also implementSerializable<R> Traversable<R>Evaluate a read-writeFunctionoperation with theEntryView.ReadWriteEntryViewof the value associated with the key, for all existing keys, and returns aTraversableto navigate each of theFunctioninvocation returns.default <R> Traversable<R>Same asevalAll(Function)except that the function must also implementSerializable<T,R> Traversable<R> evalMany(Map<? extends K, ? extends T> arguments, BiFunction<T, EntryView.ReadWriteEntryView<K, V>, R> f) Evaluate a read-writeBiFunction, with an argument passed in and aEntryView.ReadWriteEntryViewof the value associated with the key, for each of the keys in the set passed in, and returns anTraversableto navigate each of theBiFunctioninvocation returns.default <T,R> Traversable<R> evalMany(Map<? extends K, ? extends T> arguments, SerializableBiFunction<T, EntryView.ReadWriteEntryView<K, V>, R> f) Same asevalMany(Map, BiFunction)except that the function must also implementSerializable<R> Traversable<R>Evaluate a read-writeFunctionoperation with theEntryView.ReadWriteEntryViewof the value associated with the key, for each of the keys in the set passed in, and returns aTraversableto navigate each of theFunctioninvocation returns.default <R> Traversable<R>evalMany(Set<? extends K> keys, SerializableFunction<EntryView.ReadWriteEntryView<K, V>, R> f) Same asevalMany(Set, Function)except that the function must also implementSerializableAllows to read-write listeners to be registered.withParams(Param<?>... ps) Tweak read-write functional map executions providingParaminstances.Methods inherited from interface java.lang.AutoCloseable
closeMethods inherited from interface org.infinispan.functional.FunctionalMap
cache, getName, getStatus, isEncoded
-
Method Details
-
withParams
Tweak read-write functional map executions providingParaminstances.- Specified by:
withParamsin interfaceFunctionalMap<K,V>
-
eval
Evaluate a read-write function on the value and metadata associated with the key and return aCompletableFuturewith the return type of the function. If the user is not sure if the key is present,EntryView.ReadEntryView.find()can be used to find out for sure. This method can be used to implement single-key read-write operations inConcurrentMapandjavax.cache.Cachethat do not depend on value information given by the user such as:Map.remove(Object)javax.cache.Cache#remove(Object)javax.cache.Cache#getAndRemove(Object)javax.cache.Cache#invoke(Object, EntryProcessor, Object...)
The function must not mutate neither the key returned through
EntryView.ReadEntryView.key()nor the internally stored value provided throughEntryView.ReadEntryView.get()orEntryView.ReadEntryView.find().- Type Parameters:
R- function return type- Parameters:
key- the key associated with theEntryView.ReadWriteEntryViewto be passed to the function.f- function that takes aEntryView.ReadWriteEntryViewassociated with the key, and returns a value.- Returns:
- a
CompletableFuturewhich will be completed with the returned value from the function
-
eval
default <R> CompletableFuture<R> eval(K key, SerializableFunction<EntryView.ReadWriteEntryView<K, V>, R> f) Same aseval(Object, Function)except that the function must also implementSerializableThe compiler will pick this overload for lambda parameters, making them
Serializable -
eval
<T,R> CompletableFuture<R> eval(K key, T argument, BiFunction<T, EntryView.ReadWriteEntryView<K, V>, R> f) Evaluate a read-write function, with an argument passed in and aEntryView.WriteEntryViewof the value associated with the key, and return aCompletableFuturewhich will be completed with the returned value by the function.This method provides the the capability to both update the value and metadata associated with that key, and return previous value or metadata.
This method can be used to implement the vast majority of single-key read-write operations in
ConcurrentMapandjavax.cache.Cachesuch as:Map.put(Object, Object)ConcurrentMap.putIfAbsent(Object, Object)ConcurrentMap.replace(Object, Object)ConcurrentMap.replace(Object, Object, Object)ConcurrentMap.remove(Object, Object)javax.cache.Cache#getAndPut(Object, Object)javax.cache.Cache#putIfAbsent(Object, Object)javax.cache.Cache#remove(Object, Object)javax.cache.Cache#replace(Object, Object, Object)javax.cache.Cache#replace(Object, Object)javax.cache.Cache#getAndReplace(Object, Object)
The functionality provided by this function could indeed be implemented with
eval(Object, Function), but there's a crucial difference. If you want to store a value and reference the value to be stored from the passed in operation,eval(Object, Function)needs to capture that value. Capturing means that each time the operation is called, a new lambda needs to be instantiated. By offering aBiFunctionthat takes user provided value as first parameter, the operation does not capture any external objects when implementing simple operations such asjavax.cache.Cache#getAndPut(Object, Object), and hence, theBiFunctioncould be cached and reused each time it's invoked.Note that when
encodersare in place despite the argument type and value type don't have to match the argument will use value encoding.The function must not mutate neither the key returned through
EntryView.ReadEntryView.key()nor the internally stored value provided throughEntryView.ReadEntryView.get()orEntryView.ReadEntryView.find().- Type Parameters:
R- type of the function's return- Parameters:
key- the key associated with theEntryView.ReadWriteEntryViewto be passed to the operationargument- argument passed in as first parameter to theBiFunction.f- operation that takes a user defined value, and aEntryView.ReadWriteEntryViewassociated with the key, and writes to theEntryView.ReadWriteEntryViewpassed in, possibly returning previously stored value or metadata information- Returns:
- a
CompletableFuturewhich will be completed with the returned value from the function
-
eval
default <T,R> CompletableFuture<R> eval(K key, T argument, SerializableBiFunction<T, EntryView.ReadWriteEntryView<K, V>, R> f) Same aseval(Object, Object, BiFunction)except that the function must also implementSerializableThe compiler will pick this overload for lambda parameters, making them
Serializable -
evalMany
<T,R> Traversable<R> evalMany(Map<? extends K, ? extends T> arguments, BiFunction<T, EntryView.ReadWriteEntryView<K, V>, R> f) Evaluate a read-writeBiFunction, with an argument passed in and aEntryView.ReadWriteEntryViewof the value associated with the key, for each of the keys in the set passed in, and returns anTraversableto navigate each of theBiFunctioninvocation returns.This method can be used to implement operations that store a set of keys and return previous values or metadata parameters.
These kind of operations are preferred to traditional end user iterations because the internal logic can often iterate more efficiently since it knows more about the system.
Note that when
encodersare in place despite the argument type and value type don't have to match the argument will use value encoding.The function must not mutate neither the key returned through
EntryView.ReadEntryView.key()nor the internally stored value provided throughEntryView.ReadEntryView.get()orEntryView.ReadEntryView.find().- Parameters:
arguments- the key/value pairs associated with each of theEntryView.ReadWriteEntryViewpassed in the function callbacksf- function that takes in a value associated with a key in the entries collection and theEntryView.ReadWriteEntryViewassociated with that key in the cache- Returns:
- a
Traversableto navigate eachBiFunctionreturn
-
evalMany
default <T,R> Traversable<R> evalMany(Map<? extends K, ? extends T> arguments, SerializableBiFunction<T, EntryView.ReadWriteEntryView<K, V>, R> f) Same asevalMany(Map, BiFunction)except that the function must also implementSerializableThe compiler will pick this overload for lambda parameters, making them
Serializable -
evalMany
Evaluate a read-writeFunctionoperation with theEntryView.ReadWriteEntryViewof the value associated with the key, for each of the keys in the set passed in, and returns aTraversableto navigate each of theFunctioninvocation returns.This method can be used to implement operations such as
javax.cache.Cache#invokeAll(Set, EntryProcessor, Object...), or a remove a set of keys returning previous values or metadata parameters.The function must not mutate neither the key returned through
EntryView.ReadEntryView.key()nor the internally stored value provided throughEntryView.ReadEntryView.get()orEntryView.ReadEntryView.find().- Parameters:
keys- the keys associated with each of theEntryView.ReadWriteEntryViewpassed in the function callbacksf- function that theEntryView.ReadWriteEntryViewassociated with one of the keys passed in, and returns a value- Returns:
- a
Traversableto navigate eachFunctionreturn
-
evalMany
default <R> Traversable<R> evalMany(Set<? extends K> keys, SerializableFunction<EntryView.ReadWriteEntryView<K, V>, R> f) Same asevalMany(Set, Function)except that the function must also implementSerializableThe compiler will pick this overload for lambda parameters, making them
Serializable -
evalAll
Evaluate a read-writeFunctionoperation with theEntryView.ReadWriteEntryViewof the value associated with the key, for all existing keys, and returns aTraversableto navigate each of theFunctioninvocation returns.This method can be used to an operation that removes all cached entries individually, and returns previous value and/or metadata parameters.
The function must not mutate neither the key returned through
EntryView.ReadEntryView.key()nor the internally stored value provided throughEntryView.ReadEntryView.get()orEntryView.ReadEntryView.find().- Returns:
- a
Traversableto navigate eachFunctionreturn
-
evalAll
Same asevalAll(Function)except that the function must also implementSerializableThe compiler will pick this overload for lambda parameters, making them
Serializable -
listeners
Listeners.ReadWriteListeners<K,V> listeners()Allows to read-write listeners to be registered.
-