Class ReadOnlyMapImpl<K,V>
- java.lang.Object
-
- org.infinispan.functional.impl.ReadOnlyMapImpl<K,V>
-
- All Implemented Interfaces:
AutoCloseable,FunctionalMap<K,V>,FunctionalMap.ReadOnlyMap<K,V>
@Experimental public final class ReadOnlyMapImpl<K,V> extends Object implements FunctionalMap.ReadOnlyMap<K,V>
Read-only map implementation.- 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>
-
-
Field Summary
Fields Modifier and Type Field Description protected FunctionalMapImpl<K,V>fmapprotected DataConversionkeyDataConversionprotected Paramsparamsprotected DataConversionvalueDataConversion
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()static <K,V>
FunctionalMap.ReadOnlyMap<K,V>create(FunctionalMapImpl<K,V> functionalMap)protected Map<?,?>encodeEntries(Map<? extends K,?> entries)protected Set<?>encodeKeys(Set<? extends K> keys)Traversable<EntryView.ReadEntryView<K,V>>entries()Provides aTraversablethat 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 aCompletableFuturewith the return type of the function.<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 anTraversableto work on each computed function's result.protected InvocationContextgetInvocationContext(boolean isWrite, int keyCount)StringgetName()Functional map's name.ComponentStatusgetStatus()Functional map's status.protected <T> CompletableFuture<T>invokeAsync(InvocationContext ctx, VisitableCommand cmd)Traversable<K>keys()Provides aTraversablethat allows clients to navigate all cached keys.FunctionalMap.ReadOnlyMap<K,V>withParams(Param<?>... ps)Tweak read-only functional map executions providingParaminstances.-
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
getName, getStatus, isEncoded
-
Methods inherited from interface org.infinispan.functional.FunctionalMap.ReadOnlyMap
eval, evalMany
-
-
-
-
Field Detail
-
fmap
protected final FunctionalMapImpl<K,V> fmap
-
params
protected final Params params
-
keyDataConversion
protected final DataConversion keyDataConversion
-
valueDataConversion
protected final DataConversion valueDataConversion
-
-
Method Detail
-
create
public static <K,V> FunctionalMap.ReadOnlyMap<K,V> create(FunctionalMapImpl<K,V> functionalMap)
-
eval
public <R> CompletableFuture<R> eval(K key, Function<EntryView.ReadEntryView<K,V>,R> f)
Description copied from interface:FunctionalMap.ReadOnlyMapEvaluate a read-only function on the value 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. Typically, function implementations would return value orMetaParaminformation from the cache entry in the functional map.By returning
CompletableFutureinstead 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
ConcurrentMapand 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().- Specified by:
evalin interfaceFunctionalMap.ReadOnlyMap<K,V>- Type Parameters:
R- function return type- Parameters:
key- the key associated with theEntryView.ReadEntryViewto be passed to the function.f- function that takes aEntryView.ReadEntryViewassociated with the key, and returns a value.- Returns:
- a
CompletableFuturewhich will be completed with the returned value from the function
-
evalMany
public <R> Traversable<R> evalMany(Set<? extends K> keys, Function<EntryView.ReadEntryView<K,V>,R> f)
Description copied from interface:FunctionalMap.ReadOnlyMapEvaluate 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 anTraversableto 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
FunctionalMap.ReadOnlyMap.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().- Specified by:
evalManyin interfaceFunctionalMap.ReadOnlyMap<K,V>- Type Parameters:
R- function return type- Parameters:
keys- the keys associated with each of theEntryView.ReadEntryViewpassed in the function callbacksf- function that takes aEntryView.ReadEntryViewassociated with the key, and returns a value. It'll be invoked once for each key passed in- Returns:
- a sequential
Traversablethat can be navigated to retrieve each function return value
-
keys
public Traversable<K> keys()
Description copied from interface:FunctionalMap.ReadOnlyMapProvides aTraversablethat allows clients to navigate all cached keys.This method can be used to implement operations such as:
- Specified by:
keysin interfaceFunctionalMap.ReadOnlyMap<K,V>- Returns:
- a sequential
Traversableto navigate each cached key
-
entries
public Traversable<EntryView.ReadEntryView<K,V>> entries()
Description copied from interface:FunctionalMap.ReadOnlyMapProvides aTraversablethat 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()
- Specified by:
entriesin interfaceFunctionalMap.ReadOnlyMap<K,V>- Returns:
- a sequential
Traversableto navigate each cached entry
-
withParams
public FunctionalMap.ReadOnlyMap<K,V> withParams(Param<?>... ps)
Description copied from interface:FunctionalMap.ReadOnlyMapTweak read-only functional map executions providingParaminstances.- Specified by:
withParamsin interfaceFunctionalMap<K,V>- Specified by:
withParamsin interfaceFunctionalMap.ReadOnlyMap<K,V>
-
getName
public String getName()
Description copied from interface:FunctionalMapFunctional map's name.- Specified by:
getNamein interfaceFunctionalMap<K,V>
-
getStatus
public ComponentStatus getStatus()
Description copied from interface:FunctionalMapFunctional map's status.- Specified by:
getStatusin interfaceFunctionalMap<K,V>
-
close
public void close() throws Exception- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
getInvocationContext
protected InvocationContext getInvocationContext(boolean isWrite, int keyCount)
-
invokeAsync
protected <T> CompletableFuture<T> invokeAsync(InvocationContext ctx, VisitableCommand cmd)
-
-