@Experimental public final class ReadOnlyMapImpl<K,V> extends Object implements FunctionalMap.ReadOnlyMap<K,V>
FunctionalMap.ReadOnlyMap<K,V>, FunctionalMap.ReadWriteMap<K,V>, FunctionalMap.WriteOnlyMap<K,V>
Modifier and Type | Field and Description |
---|---|
protected FunctionalMapImpl<K,V> |
fmap |
protected DataConversion |
keyDataConversion |
protected Params |
params |
protected DataConversion |
valueDataConversion |
Modifier and Type | Method and Description |
---|---|
void |
close() |
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 a
Traversable 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 a
CompletableFuture with 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 an
Traversable to work on each computed function's result. |
protected InvocationContext |
getInvocationContext(boolean isWrite,
int keyCount) |
String |
getName()
Functional map's name.
|
ComponentStatus |
getStatus()
Functional map's status.
|
protected <T> CompletableFuture<T> |
invokeAsync(InvocationContext ctx,
VisitableCommand cmd) |
Traversable<K> |
keys()
Provides a
Traversable that allows clients to navigate all cached keys. |
FunctionalMap.ReadOnlyMap<K,V> |
withParams(Param<?>... ps)
Tweak read-only functional map executions providing
Param instances. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
eval, evalMany
getName, getStatus, isEncoded
close
protected final FunctionalMapImpl<K,V> fmap
protected final Params params
protected final DataConversion keyDataConversion
protected final DataConversion valueDataConversion
public static <K,V> FunctionalMap.ReadOnlyMap<K,V> create(FunctionalMapImpl<K,V> functionalMap)
public <R> CompletableFuture<R> eval(K key, Function<EntryView.ReadEntryView<K,V>,R> f)
FunctionalMap.ReadOnlyMap
CompletableFuture
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 or MetaParam
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
through EntryView.ReadEntryView.get()
or EntryView.ReadEntryView.find()
.
eval
in interface FunctionalMap.ReadOnlyMap<K,V>
R
- function return typekey
- the key associated with the EntryView.ReadEntryView
to be
passed to the function.f
- function that takes a EntryView.ReadEntryView
associated with
the key, and returns a value.CompletableFuture
which will be completed with the
returned value from the functionpublic <R> Traversable<R> evalMany(Set<? extends K> keys, Function<EntryView.ReadEntryView<K,V>,R> f)
FunctionalMap.ReadOnlyMap
Traversable
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 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:
The function must not mutate neither the key returned through
EntryView.ReadEntryView.key()
nor the internally stored value provided
through EntryView.ReadEntryView.get()
or EntryView.ReadEntryView.find()
.
evalMany
in interface FunctionalMap.ReadOnlyMap<K,V>
R
- function return typekeys
- the keys associated with each of the EntryView.ReadEntryView
passed in the function callbacksf
- function that takes a EntryView.ReadEntryView
associated with
the key, and returns a value. It'll be invoked once for each key
passed inTraversable
that can be navigated to
retrieve each function return valuepublic Traversable<K> keys()
FunctionalMap.ReadOnlyMap
Traversable
that allows clients to navigate all cached keys.
This method can be used to implement operations such as:
keys
in interface FunctionalMap.ReadOnlyMap<K,V>
Traversable
to navigate each cached keypublic Traversable<EntryView.ReadEntryView<K,V>> entries()
FunctionalMap.ReadOnlyMap
Traversable
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()
entries
in interface FunctionalMap.ReadOnlyMap<K,V>
Traversable
to navigate each cached entrypublic FunctionalMap.ReadOnlyMap<K,V> withParams(Param<?>... ps)
FunctionalMap.ReadOnlyMap
Param
instances.withParams
in interface FunctionalMap<K,V>
withParams
in interface FunctionalMap.ReadOnlyMap<K,V>
public String getName()
FunctionalMap
getName
in interface FunctionalMap<K,V>
public ComponentStatus getStatus()
FunctionalMap
getStatus
in interface FunctionalMap<K,V>
public void close() throws Exception
close
in interface AutoCloseable
Exception
protected InvocationContext getInvocationContext(boolean isWrite, int keyCount)
protected <T> CompletableFuture<T> invokeAsync(InvocationContext ctx, VisitableCommand cmd)
Copyright © 2021 JBoss by Red Hat. All rights reserved.