@Experimental public static interface FunctionalMap.WriteOnlyMap<K,V> extends FunctionalMap<K,V>
EntryView.WriteEntryView
.
Write-only operations require locks to be acquired but crucially they do not require reading previous value or metadata parameter information associated with the cached entry, which sometimes can be expensive since they involve talking to a remote node in the cluster or the persistence layer So, exposing write-only operations makes it easy to take advantage of this important optimisation.
Method parameters for write-only operations, including lambdas, must be marshallable when running in a cluster.
FunctionalMap.ReadOnlyMap<K,V>, FunctionalMap.ReadWriteMap<K,V>, FunctionalMap.WriteOnlyMap<K,V>
Modifier and Type | Method and Description |
---|---|
CompletableFuture<Void> |
eval(K key,
Consumer<EntryView.WriteEntryView<K,V>> f)
Evaluate a write-only
Consumer operation with a
EntryView.WriteEntryView of the value associated with the key,
and return a CompletableFuture which will be
completed with the object returned by the operation. |
default CompletableFuture<Void> |
eval(K key,
SerializableConsumer<EntryView.WriteEntryView<K,V>> f)
Same as
eval(Object, Consumer) except that the function must also
implement Serializable |
<T> CompletableFuture<Void> |
eval(K key,
T argument,
BiConsumer<T,EntryView.WriteEntryView<K,V>> f)
Evaluate a write-only
BiConsumer operation, with an argument
passed in and a EntryView.WriteEntryView of the value associated with
the key, and return a CompletableFuture which will be
completed when the operation completes. |
default <T> CompletableFuture<Void> |
eval(K key,
T argument,
SerializableBiConsumer<T,EntryView.WriteEntryView<K,V>> f)
Same as
eval(Object, Object, BiConsumer) except that the function must also
implement Serializable |
CompletableFuture<Void> |
evalAll(Consumer<EntryView.WriteEntryView<K,V>> f)
Evaluate a write-only
Consumer operation with the
EntryView.WriteEntryView of the value associated with the key, for all
existing keys in functional map, and returns a CompletableFuture
that will be completed when the write-only operation has been executed
against all the entries. |
default CompletableFuture<Void> |
evalAll(SerializableConsumer<EntryView.WriteEntryView<K,V>> f)
Same as
evalAll(Consumer) except that the function must also
implement Serializable |
<T> CompletableFuture<Void> |
evalMany(Map<? extends K,? extends T> arguments,
BiConsumer<T,EntryView.WriteEntryView<K,V>> f)
Evaluate a write-only
BiConsumer operation, with an argument
passed in and a EntryView.WriteEntryView of the value associated with
the key, for each of the keys in the set passed in, and returns a
CompletableFuture that will be completed when the write-only
operation has been executed against all the entries. |
default <T> CompletableFuture<Void> |
evalMany(Map<? extends K,? extends T> arguments,
SerializableBiConsumer<T,EntryView.WriteEntryView<K,V>> f)
Same as
evalMany(Map, BiConsumer) except that the function must also
implement Serializable |
CompletableFuture<Void> |
evalMany(Set<? extends K> keys,
Consumer<EntryView.WriteEntryView<K,V>> f)
Evaluate a write-only
Consumer operation with the
EntryView.WriteEntryView of the value associated with the key, for each
of the keys in the set passed in, and returns a
CompletableFuture that will be completed when the write-only
operation has been executed against all the entries. |
default CompletableFuture<Void> |
evalMany(Set<? extends K> keys,
SerializableConsumer<EntryView.WriteEntryView<K,V>> f)
Same as
evalMany(Set, Consumer) except that the function must also
implement Serializable |
Listeners.WriteListeners<K,V> |
listeners()
Allows to write-only listeners to be registered.
|
CompletableFuture<Void> |
truncate()
Truncate the contents of the cache, returning a
CompletableFuture
that will be completed when the truncate process completes. |
FunctionalMap.WriteOnlyMap<K,V> |
withParams(Param<?>... ps)
Tweak write-only functional map executions providing
Param instances. |
getName, getStatus, isEncoded
close
FunctionalMap.WriteOnlyMap<K,V> withParams(Param<?>... ps)
Param
instances.withParams
in interface FunctionalMap<K,V>
<T> CompletableFuture<Void> eval(K key, T argument, BiConsumer<T,EntryView.WriteEntryView<K,V>> f)
BiConsumer
operation, with an argument
passed in and a EntryView.WriteEntryView
of the value associated with
the key, and return a CompletableFuture
which will be
completed when the operation completes.
Since this is a write-only operation, no entry attributes can be queried, hence the only reasonable thing can be returned is Void.
This method can be used to implement single-key write-only operations
which do not need to query previous value, such as
javax.cache.Cache#put(Object, Object)
This operation is very similar to eval(Object, Consumer)
and in fact, the functionality provided by this function could indeed
be implemented with eval(Object, Consumer)
, 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,
eval(Object, Consumer)
needs to capture that value.
Capturing means that each time the operation is called, a new lambda
needs to be instantiated. By offering a BiConsumer
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#put(Object, Object)
, and hence, the
BiConsumer
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.
key
- the key associated with the EntryView.WriteEntryView
to be
passed to the operationargument
- argument passed in as first parameter to the
BiConsumer
operation.f
- operation that takes a user defined value, and a
EntryView.WriteEntryView
associated with the key, and writes
to the EntryView.WriteEntryView
passed in without returning anythingCompletableFuture
which will be completed when the
operation completesdefault <T> CompletableFuture<Void> eval(K key, T argument, SerializableBiConsumer<T,EntryView.WriteEntryView<K,V>> f)
eval(Object, Object, BiConsumer)
except that the function must also
implement Serializable
The compiler will pick this overload for lambda parameters, making them Serializable
CompletableFuture<Void> eval(K key, Consumer<EntryView.WriteEntryView<K,V>> f)
Consumer
operation with a
EntryView.WriteEntryView
of the value associated with the key,
and return a CompletableFuture
which will be
completed with the object returned by the operation.
Since this is a write-only operation, no entry attributes can be queried, hence the only reasonable thing can be returned is Void.
This operation can be used to either remove a cached entry, or to write a constant value along with optional metadata parameters.
key
- the key associated with the EntryView.WriteEntryView
to be
passed to the operationf
- operation that takes a EntryView.WriteEntryView
associated with
the key and writes to the it without returning anythingCompletableFuture
which will be completed when the
operation completesdefault CompletableFuture<Void> eval(K key, SerializableConsumer<EntryView.WriteEntryView<K,V>> f)
eval(Object, Consumer)
except that the function must also
implement Serializable
The compiler will pick this overload for lambda parameters, making them Serializable
<T> CompletableFuture<Void> evalMany(Map<? extends K,? extends T> arguments, BiConsumer<T,EntryView.WriteEntryView<K,V>> f)
BiConsumer
operation, with an argument
passed in and a EntryView.WriteEntryView
of the value associated with
the key, for each of the keys in the set passed in, and returns a
CompletableFuture
that will be completed when the write-only
operation has been executed against all the entries.
This method can be used to implement operations such as:
Map.putAll(Map)
javax.cache.Cache#putAll(Map)
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.
Since this is a write-only operation, no entry attributes can be queried, hence the only reasonable thing can be returned is Void.
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.
arguments
- the key/value pairs associated with each of the
EntryView.WriteEntryView
passed in the function callbacksf
- operation that consumes a value associated with a key in the
entries collection and the EntryView.WriteEntryView
associated
with that key in the cacheCompletableFuture
which will be completed when
the BiConsumer
operation has been executed against
all entriesdefault <T> CompletableFuture<Void> evalMany(Map<? extends K,? extends T> arguments, SerializableBiConsumer<T,EntryView.WriteEntryView<K,V>> f)
evalMany(Map, BiConsumer)
except that the function must also
implement Serializable
The compiler will pick this overload for lambda parameters, making them Serializable
CompletableFuture<Void> evalMany(Set<? extends K> keys, Consumer<EntryView.WriteEntryView<K,V>> f)
Consumer
operation with the
EntryView.WriteEntryView
of the value associated with the key, for each
of the keys in the set passed in, and returns a
CompletableFuture
that will be completed when the write-only
operation has been executed against all the entries.
This method can be used to implement operations such as
javax.cache.Cache#removeAll(Set)
.
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.
Since this is a write-only operation, no entry attributes can be queried, hence the only reasonable thing can be returned is Void.
keys
- the keys associated with each of the EntryView.WriteEntryView
passed in the function callbacksf
- operation that the EntryView.WriteEntryView
associated with
one of the keys passed inCompletableFuture
which will be completed when
the Consumer
operation has been executed against all
entriesdefault CompletableFuture<Void> evalMany(Set<? extends K> keys, SerializableConsumer<EntryView.WriteEntryView<K,V>> f)
evalMany(Set, Consumer)
except that the function must also
implement Serializable
The compiler will pick this overload for lambda parameters, making them Serializable
CompletableFuture<Void> evalAll(Consumer<EntryView.WriteEntryView<K,V>> f)
Consumer
operation with the
EntryView.WriteEntryView
of the value associated with the key, for all
existing keys in functional map, and returns a CompletableFuture
that will be completed when the write-only operation has been executed
against all the entries.
This method can be used to implement operations such as
javax.cache.Cache#removeAll()
.
f
- operation that the EntryView.WriteEntryView
associated with
one of the keys passed inCompletableFuture
which will be completed when
the Consumer
operation has been executed against all
entriesdefault CompletableFuture<Void> evalAll(SerializableConsumer<EntryView.WriteEntryView<K,V>> f)
evalAll(Consumer)
except that the function must also
implement Serializable
The compiler will pick this overload for lambda parameters, making them Serializable
CompletableFuture<Void> truncate()
CompletableFuture
that will be completed when the truncate process completes.
This method can be used to implement:
Map.clear()
javax.cache.Cache#clear()
CompletableFuture
that completes when the truncat
has finishedListeners.WriteListeners<K,V> listeners()
Copyright © 2021 JBoss by Red Hat. All rights reserved.