@Experimental public final class ReadWriteMapImpl<K,V> extends Object implements FunctionalMap.ReadWriteMap<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.ReadWriteMap<K,V> |
create(FunctionalMapImpl<K,V> functionalMap) |
protected Map<?,?> |
encodeEntries(Map<? extends K,?> entries) |
protected Set<?> |
encodeKeys(Set<? extends K> keys) |
<R> CompletableFuture<R> |
eval(K key,
Function<EntryView.ReadWriteEntryView<K,V>,R> f)
Evaluate a read-write function on the value and metadata associated
with the key and return a
CompletableFuture 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 a
EntryView.WriteEntryView of the value associated with the key, and
return a CompletableFuture which will be completed with the
returned value by the function. |
<R> Traversable<R> |
evalAll(Function<EntryView.ReadWriteEntryView<K,V>,R> f)
Evaluate a read-write
Function operation with the
EntryView.ReadWriteEntryView of the value associated with the key, for all
existing keys, and returns a Traversable to navigate each of
the Function invocation returns. |
<T,R> Traversable<R> |
evalMany(Map<? extends K,? extends T> arguments,
BiFunction<T,EntryView.ReadWriteEntryView<K,V>,R> f)
Evaluate a read-write
BiFunction , with an argument passed in and
a EntryView.ReadWriteEntryView of the value associated with
the key, for each of the keys in the set passed in, and
returns an Traversable to navigate each of the
BiFunction invocation returns. |
<R> Traversable<R> |
evalMany(Set<? extends K> keys,
Function<EntryView.ReadWriteEntryView<K,V>,R> f)
Evaluate a read-write
Function operation with the
EntryView.ReadWriteEntryView of the value associated with the key, for each
of the keys in the set passed in, and returns a Traversable
to navigate each of the Function invocation returns. |
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) |
Listeners.ReadWriteListeners<K,V> |
listeners()
Allows to read-write listeners to be registered.
|
FunctionalMap.ReadWriteMap<K,V> |
withParams(Param<?>... ps)
Tweak read-write functional map executions providing
Param instances. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
eval, eval, evalAll, evalMany, 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.ReadWriteMap<K,V> create(FunctionalMapImpl<K,V> functionalMap)
public <R> CompletableFuture<R> eval(K key, Function<EntryView.ReadWriteEntryView<K,V>,R> f)
FunctionalMap.ReadWriteMap
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.
This method can be used to implement single-key read-write operations
in ConcurrentMap
and javax.cache.Cache
that 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
through EntryView.ReadEntryView.get()
or EntryView.ReadEntryView.find()
.
eval
in interface FunctionalMap.ReadWriteMap<K,V>
R
- function return typekey
- the key associated with the EntryView.ReadWriteEntryView
to be
passed to the function.f
- function that takes a EntryView.ReadWriteEntryView
associated with
the key, and returns a value.CompletableFuture
which will be completed with the
returned value from the functionpublic <T,R> CompletableFuture<R> eval(K key, T argument, BiFunction<T,EntryView.ReadWriteEntryView<K,V>,R> f)
FunctionalMap.ReadWriteMap
EntryView.WriteEntryView
of the value associated with the key, and
return a CompletableFuture
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
and javax.cache.Cache
such 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 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 a BiFunction
that
takes user provided value as first parameter, the operation does
not capture any external objects when implementing
simple operations such as javax.cache.Cache#getAndPut(Object, Object)
,
and hence, the BiFunction
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
through EntryView.ReadEntryView.get()
or EntryView.ReadEntryView.find()
.
eval
in interface FunctionalMap.ReadWriteMap<K,V>
R
- type of the function's returnkey
- the key associated with the EntryView.ReadWriteEntryView
to be
passed to the operationargument
- argument passed in as first parameter to the BiFunction
.f
- operation that takes a user defined value, and a
EntryView.ReadWriteEntryView
associated with the key, and writes
to the EntryView.ReadWriteEntryView
passed in, possibly
returning previously stored value or metadata informationCompletableFuture
which will be completed with the
returned value from the functionpublic <T,R> Traversable<R> evalMany(Map<? extends K,? extends T> arguments, BiFunction<T,EntryView.ReadWriteEntryView<K,V>,R> f)
FunctionalMap.ReadWriteMap
BiFunction
, with an argument passed in and
a EntryView.ReadWriteEntryView
of the value associated with
the key, for each of the keys in the set passed in, and
returns an Traversable
to navigate each of the
BiFunction
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
through EntryView.ReadEntryView.get()
or EntryView.ReadEntryView.find()
.
evalMany
in interface FunctionalMap.ReadWriteMap<K,V>
arguments
- the key/value pairs associated with each of the
EntryView.ReadWriteEntryView
passed in the function callbacksf
- function that takes in a value associated with a key in the
entries collection and the EntryView.ReadWriteEntryView
associated
with that key in the cacheTraversable
to navigate each BiFunction
returnpublic <R> Traversable<R> evalMany(Set<? extends K> keys, Function<EntryView.ReadWriteEntryView<K,V>,R> f)
FunctionalMap.ReadWriteMap
Function
operation with the
EntryView.ReadWriteEntryView
of the value associated with the key, for each
of the keys in the set passed in, and returns a Traversable
to navigate each of the Function
invocation 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
through EntryView.ReadEntryView.get()
or EntryView.ReadEntryView.find()
.
evalMany
in interface FunctionalMap.ReadWriteMap<K,V>
keys
- the keys associated with each of the EntryView.ReadWriteEntryView
passed in the function callbacksf
- function that the EntryView.ReadWriteEntryView
associated with
one of the keys passed in, and returns a valueTraversable
to navigate each Function
returnpublic <R> Traversable<R> evalAll(Function<EntryView.ReadWriteEntryView<K,V>,R> f)
FunctionalMap.ReadWriteMap
Function
operation with the
EntryView.ReadWriteEntryView
of the value associated with the key, for all
existing keys, and returns a Traversable
to navigate each of
the Function
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
through EntryView.ReadEntryView.get()
or EntryView.ReadEntryView.find()
.
evalAll
in interface FunctionalMap.ReadWriteMap<K,V>
Traversable
to navigate each Function
returnpublic Listeners.ReadWriteListeners<K,V> listeners()
FunctionalMap.ReadWriteMap
listeners
in interface FunctionalMap.ReadWriteMap<K,V>
public FunctionalMap.ReadWriteMap<K,V> withParams(Param<?>... ps)
FunctionalMap.ReadWriteMap
Param
instances.withParams
in interface FunctionalMap<K,V>
withParams
in interface FunctionalMap.ReadWriteMap<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.