Class SimpleReadWriteMapImpl<K,V>
- All Implemented Interfaces:
AutoCloseable
,FunctionalMap<K,
,V> FunctionalMap.ReadWriteMap<K,
V>
ReadWriteMapImpl
that works with a simple cache.- Since:
- 15.0
- Author:
- José Bolina
- See Also:
-
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> -
Field Summary
Modifier and TypeFieldDescriptionprotected final FunctionalMapImpl
<K, V> protected final DataConversion
protected final Params
protected final DataConversion
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncache()
void
close()
protected Map
<?, ?> encodeEntries
(Map<? extends K, ?> entries) protected Set
<?> encodeKeys
(Set<? extends K> keys) <R> CompletableFuture
<R> Evaluate a read-write function on the value and metadata associated with the key and return aCompletableFuture
with the return type of the function.<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.WriteEntryView
of the value associated with the key, and return aCompletableFuture
which will be completed with the returned value by the function.<R> Traversable
<R> Evaluate a read-writeFunction
operation with theEntryView.ReadWriteEntryView
of the value associated with the key, for all existing keys, and returns aTraversable
to navigate each of theFunction
invocation returns.<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.ReadWriteEntryView
of the value associated with the key, for each of the keys in the set passed in, and returns anTraversable
to navigate each of theBiFunction
invocation returns.<R> Traversable
<R> Evaluate a read-writeFunction
operation with theEntryView.ReadWriteEntryView
of the value associated with the key, for each of the keys in the set passed in, and returns aTraversable
to navigate each of theFunction
invocation returns.protected InvocationContext
getInvocationContext
(boolean isWrite, int keyCount) getName()
Functional map's name.Functional map's status.protected <T> CompletableFuture
<T> invokeAsync
(InvocationContext ctx, VisitableCommand cmd) readCacheEntry
(K key, InternalCacheEntry<K, V> ice) default <R> R
default K
toStorageKey
(K key) Methods inherited from class org.infinispan.functional.impl.ReadWriteMapImpl
create, listeners, withParams
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.AutoCloseable
close
Methods inherited from interface org.infinispan.functional.FunctionalMap
cache, getName, getStatus, isEncoded
-
Field Details
-
fmap
-
params
-
keyDataConversion
-
valueDataConversion
-
-
Constructor Details
-
SimpleReadWriteMapImpl
-
-
Method Details
-
eval
Description copied from interface:FunctionalMap.ReadWriteMap
Evaluate a read-write function on the value and metadata associated with the key and return aCompletableFuture
with 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 inConcurrentMap
that do not depend on value information given by the user such as: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()
.- Specified by:
eval
in interfaceFunctionalMap.ReadWriteMap<K,
V> - Overrides:
eval
in classReadWriteMapImpl<K,
V> - Type Parameters:
R
- function return type- Parameters:
key
- the key associated with theEntryView.ReadWriteEntryView
to be passed to the function.f
- function that takes aEntryView.ReadWriteEntryView
associated with the key, and returns a value.- Returns:
- a
CompletableFuture
which will be completed with the returned value from the function
-
eval
public <T,R> CompletableFuture<R> eval(K key, T argument, BiFunction<T, EntryView.ReadWriteEntryView<K, V>, R> f) Description copied from interface:FunctionalMap.ReadWriteMap
Evaluate a read-write function, with an argument passed in and aEntryView.WriteEntryView
of the value associated with the key, and return aCompletableFuture
which 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
ConcurrentMap
such as:Map.put(Object, Object)
ConcurrentMap.putIfAbsent(Object, Object)
ConcurrentMap.replace(Object, Object)
ConcurrentMap.replace(Object, Object, Object)
ConcurrentMap.remove(Object, Object)
The functionality provided by this function could indeed be implemented with
FunctionalMap.ReadWriteMap.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,FunctionalMap.ReadWriteMap.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 aBiFunction
that takes user provided value as first parameter, the operation does not capture any external objects when implementing simple operations, and hence, theBiFunction
could be cached and reused each time it's invoked.Note that when
encoders
are 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()
.- Specified by:
eval
in interfaceFunctionalMap.ReadWriteMap<K,
V> - Overrides:
eval
in classReadWriteMapImpl<K,
V> - Type Parameters:
R
- type of the function's return- Parameters:
key
- the key associated with theEntryView.ReadWriteEntryView
to be passed to the operationargument
- argument passed in as first parameter to theBiFunction
.f
- operation that takes a user defined value, and aEntryView.ReadWriteEntryView
associated with the key, and writes to theEntryView.ReadWriteEntryView
passed in, possibly returning previously stored value or metadata information- Returns:
- a
CompletableFuture
which will be completed with the returned value from the function
-
evalMany
public <T,R> Traversable<R> evalMany(Map<? extends K, ? extends T> arguments, BiFunction<T, EntryView.ReadWriteEntryView<K, V>, R> f) Description copied from interface:FunctionalMap.ReadWriteMap
Evaluate a read-writeBiFunction
, with an argument passed in and aEntryView.ReadWriteEntryView
of the value associated with the key, for each of the keys in the set passed in, and returns anTraversable
to navigate each of theBiFunction
invocation 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
encoders
are 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()
.- Specified by:
evalMany
in interfaceFunctionalMap.ReadWriteMap<K,
V> - Overrides:
evalMany
in classReadWriteMapImpl<K,
V> - Parameters:
arguments
- the key/value pairs associated with each of theEntryView.ReadWriteEntryView
passed in the function callbacksf
- function that takes in a value associated with a key in the entries collection and theEntryView.ReadWriteEntryView
associated with that key in the cache- Returns:
- a
Traversable
to navigate eachBiFunction
return
-
evalMany
public <R> Traversable<R> evalMany(Set<? extends K> keys, Function<EntryView.ReadWriteEntryView<K, V>, R> f) Description copied from interface:FunctionalMap.ReadWriteMap
Evaluate a read-writeFunction
operation with theEntryView.ReadWriteEntryView
of the value associated with the key, for each of the keys in the set passed in, and returns aTraversable
to navigate each of theFunction
invocation returns.This method can be used to 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()
.- Specified by:
evalMany
in interfaceFunctionalMap.ReadWriteMap<K,
V> - Overrides:
evalMany
in classReadWriteMapImpl<K,
V> - Parameters:
keys
- the keys associated with each of theEntryView.ReadWriteEntryView
passed in the function callbacksf
- function that theEntryView.ReadWriteEntryView
associated with one of the keys passed in, and returns a value- Returns:
- a
Traversable
to navigate eachFunction
return
-
evalAll
Description copied from interface:FunctionalMap.ReadWriteMap
Evaluate a read-writeFunction
operation with theEntryView.ReadWriteEntryView
of the value associated with the key, for all existing keys, and returns aTraversable
to navigate each of theFunction
invocation 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()
.- Specified by:
evalAll
in interfaceFunctionalMap.ReadWriteMap<K,
V> - Overrides:
evalAll
in classReadWriteMapImpl<K,
V> - Returns:
- a
Traversable
to navigate eachFunction
return
-
toStorageKey
-
toLocalExecution
-
readCacheEntry
-
getName
Description copied from interface:FunctionalMap
Functional map's name.- Specified by:
getName
in interfaceFunctionalMap<K,
V>
-
getStatus
Description copied from interface:FunctionalMap
Functional map's status.- Specified by:
getStatus
in interfaceFunctionalMap<K,
V>
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
cache
- Specified by:
cache
in interfaceFunctionalMap<K,
V>
-
getInvocationContext
-
invokeAsync
-
encodeKeys
-
encodeEntries
-