Interface FunctionalMap.ReadOnlyMap<K,V>
-
- All Superinterfaces:
AutoCloseable
,FunctionalMap<K,V>
- Enclosing interface:
- FunctionalMap<K,V>
public static interface FunctionalMap.ReadOnlyMap<K,V> extends FunctionalMap<K,V>
Exposes read-only operations that can be executed against the functional map. The information that can be read per entry in the functional map is exposed byEntryView.ReadEntryView
.Read-only operations have the advantage that no locks are acquired for the duration of the operation and so it makes sense to have them a top-level interface dedicated to them.
Browsing methods that provide a read-only view of the cached data are available via
keys()
andentries()
. Havingkeys()
makes sense since that way keys can be traversed without having to bring values. Havingentries()
makes sense since it allows traversing both keys, values and any meta parameters associated with them, but this is no extra cost to exposing just values since keys are the main index and hence will always be available. Hence, adding a method to only browse values offers nothing extra to the API.- 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
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Traversable<EntryView.ReadEntryView<K,V>>
entries()
Provides aTraversable
that allows clients to navigate all cached entries.<R> CompletableFuture<R>
eval(K key, Function<EntryView.ReadEntryView<K,V>,R> f)
Evaluate a read-only function on the value associated with the key and return aCompletableFuture
with the return type of the function.default <R> CompletableFuture<R>
eval(K key, SerializableFunction<EntryView.ReadEntryView<K,V>,R> f)
Same aseval(Object, Function)
except that the function must also implementSerializable
<R> Traversable<R>
evalMany(Set<? extends K> keys, Function<EntryView.ReadEntryView<K,V>,R> f)
Evaluate a read-only function on a key and potential value associated in the functional map, for each of the keys in the set passed in, and returns anTraversable
to work on each computed function's result.default <R> Traversable<R>
evalMany(Set<? extends K> keys, SerializableFunction<EntryView.ReadEntryView<K,V>,R> f)
Same asevalMany(Set, Function)
except that the function must also implementSerializable
Traversable<K>
keys()
Provides aTraversable
that allows clients to navigate all cached keys.FunctionalMap.ReadOnlyMap<K,V>
withParams(Param<?>... ps)
Tweak read-only functional map executions providingParam
instances.-
Methods inherited from interface java.lang.AutoCloseable
close
-
Methods inherited from interface org.infinispan.functional.FunctionalMap
getName, getStatus, isEncoded
-
-
-
-
Method Detail
-
withParams
FunctionalMap.ReadOnlyMap<K,V> withParams(Param<?>... ps)
Tweak read-only functional map executions providingParam
instances.- Specified by:
withParams
in interfaceFunctionalMap<K,V>
-
eval
<R> CompletableFuture<R> eval(K key, Function<EntryView.ReadEntryView<K,V>,R> f)
Evaluate a read-only function on the value 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. Typically, function implementations would return value orMetaParam
information from the cache entry in the functional map.By returning
CompletableFuture
instead of the function's return type directly, the method hints at the possibility that to execute the function might require to go remote to retrieve data in persistent store or another clustered node.This method can be used to implement read-only single-key based operations in
ConcurrentMap
and javax.cache.Cache such as:Map.get(Object)
Map.containsKey(Object)
javax.cache.Cache#get(Object)
javax.cache.Cache#containsKey(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.ReadEntryView
to be passed to the function.f
- function that takes aEntryView.ReadEntryView
associated with the key, and returns a value.- Returns:
- a
CompletableFuture
which will be completed with the returned value from the function
-
eval
default <R> CompletableFuture<R> eval(K key, SerializableFunction<EntryView.ReadEntryView<K,V>,R> f)
Same aseval(Object, Function)
except that the function must also implementSerializable
The compiler will pick this overload for lambda parameters, making them
Serializable
-
evalMany
<R> Traversable<R> evalMany(Set<? extends K> keys, Function<EntryView.ReadEntryView<K,V>,R> f)
Evaluate a read-only function on a key and potential value associated in the functional map, for each of the keys in the set passed in, and returns anTraversable
to work on each computed function's result.The function passed in will be executed for as many keys present in keys collection set. Similar to
eval(Object, Function)
, if the user is not sure whether a particular key is present,EntryView.ReadEntryView.find()
can be used to find out for sure.This method can be used to implement operations such as
javax.cache.Cache#getAll(Set)
. DESIGN RATIONALE:- It makes sense to expose global operation like this instead of forcing users to iterate over the keys to lookup and call get individually since Infinispan can do things more efficiently.
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:
keys
- the keys associated with each of theEntryView.ReadEntryView
passed in the function callbacksf
- function that takes aEntryView.ReadEntryView
associated with the key, and returns a value. It'll be invoked once for each key passed in- Returns:
- a sequential
Traversable
that can be navigated to retrieve each function return value
-
evalMany
default <R> Traversable<R> evalMany(Set<? extends K> keys, SerializableFunction<EntryView.ReadEntryView<K,V>,R> f)
Same asevalMany(Set, Function)
except that the function must also implementSerializable
The compiler will pick this overload for lambda parameters, making them
Serializable
-
keys
Traversable<K> keys()
Provides aTraversable
that allows clients to navigate all cached keys.This method can be used to implement operations such as:
- Returns:
- a sequential
Traversable
to navigate each cached key
-
entries
Traversable<EntryView.ReadEntryView<K,V>> entries()
Provides aTraversable
that allows clients to navigate all cached entries.This method can be used to implement operations such as:
Map.containsValue(Object)
Map.values()
Map.entrySet()
javax.cache.Cache#iterator()
- Returns:
- a sequential
Traversable
to navigate each cached entry
-
-