Interface FunctionalMap.WriteOnlyMap<K,V>
- All Superinterfaces:
AutoCloseable
,FunctionalMap<K,
V>
- All Known Implementing Classes:
SimpleWriteOnlyMapImpl
,WriteOnlyMapImpl
- Enclosing interface:
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.
- 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
Modifier and TypeMethodDescriptionEvaluate a write-onlyConsumer
operation with aEntryView.WriteEntryView
of the value associated with the key, and return aCompletableFuture
which will be completed with the object returned by the operation.default CompletableFuture
<Void> eval
(K key, SerializableConsumer<EntryView.WriteEntryView<K, V>> f) Same aseval(Object, Consumer)
except that the function must also implementSerializable
<T> CompletableFuture
<Void> eval
(K key, T argument, BiConsumer<T, EntryView.WriteEntryView<K, V>> f) Evaluate a write-onlyBiConsumer
operation, with an argument passed in and aEntryView.WriteEntryView
of the value associated with the key, and return aCompletableFuture
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 aseval(Object, Object, BiConsumer)
except that the function must also implementSerializable
Evaluate a write-onlyConsumer
operation with theEntryView.WriteEntryView
of the value associated with the key, for all existing keys in functional map, and returns aCompletableFuture
that will be completed when the write-only operation has been executed against all the entries.default CompletableFuture
<Void> Same asevalAll(Consumer)
except that the function must also implementSerializable
<T> CompletableFuture
<Void> evalMany
(Map<? extends K, ? extends T> arguments, BiConsumer<T, EntryView.WriteEntryView<K, V>> f) Evaluate a write-onlyBiConsumer
operation, with an argument passed in and aEntryView.WriteEntryView
of the value associated with the key, for each of the keys in the set passed in, and returns aCompletableFuture
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 asevalMany(Map, BiConsumer)
except that the function must also implementSerializable
Evaluate a write-onlyConsumer
operation with theEntryView.WriteEntryView
of the value associated with the key, for each of the keys in the set passed in, and returns aCompletableFuture
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 asevalMany(Set, Consumer)
except that the function must also implementSerializable
Allows to write-only listeners to be registered.truncate()
Truncate the contents of the cache, returning aCompletableFuture
that will be completed when the truncate process completes.withParams
(Param<?>... ps) Tweak write-only functional map executions providingParam
instances.Methods inherited from interface java.lang.AutoCloseable
close
Methods inherited from interface org.infinispan.functional.FunctionalMap
cache, getName, getStatus, isEncoded
-
Method Details
-
withParams
Tweak write-only functional map executions providingParam
instances.- Specified by:
withParams
in interfaceFunctionalMap<K,
V>
-
eval
Evaluate a write-onlyBiConsumer
operation, with an argument passed in and aEntryView.WriteEntryView
of the value associated with the key, and return aCompletableFuture
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 the previous value.
This operation is very similar to
eval(Object, Consumer)
and in fact, the functionality provided by this function could indeed be implemented witheval(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 aBiConsumer
that takes user provided value as first parameter, the operation does not capture any external objects when implementing simple operations, and hence, theBiConsumer
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.- Parameters:
key
- the key associated with theEntryView.WriteEntryView
to be passed to the operationargument
- argument passed in as first parameter to theBiConsumer
operation.f
- operation that takes a user defined value, and aEntryView.WriteEntryView
associated with the key, and writes to theEntryView.WriteEntryView
passed in without returning anything- Returns:
- a
CompletableFuture
which will be completed when the operation completes
-
eval
default <T> CompletableFuture<Void> eval(K key, T argument, SerializableBiConsumer<T, EntryView.WriteEntryView<K, V>> f) Same aseval(Object, Object, BiConsumer)
except that the function must also implementSerializable
The compiler will pick this overload for lambda parameters, making them
Serializable
-
eval
Evaluate a write-onlyConsumer
operation with aEntryView.WriteEntryView
of the value associated with the key, and return aCompletableFuture
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.
- Parameters:
key
- the key associated with theEntryView.WriteEntryView
to be passed to the operationf
- operation that takes aEntryView.WriteEntryView
associated with the key and writes to the it without returning anything- Returns:
- a
CompletableFuture
which will be completed when the operation completes
-
eval
Same aseval(Object, Consumer)
except that the function must also implementSerializable
The compiler will pick this overload for lambda parameters, making them
Serializable
-
evalMany
<T> CompletableFuture<Void> evalMany(Map<? extends K, ? extends T> arguments, BiConsumer<T, EntryView.WriteEntryView<K, V>> f) Evaluate a write-onlyBiConsumer
operation, with an argument passed in and aEntryView.WriteEntryView
of the value associated with the key, for each of the keys in the set passed in, and returns aCompletableFuture
that will be completed when the write-only operation has been executed against all the entries.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.- Parameters:
arguments
- the key/value pairs associated with each of theEntryView.WriteEntryView
passed in the function callbacksf
- operation that consumes a value associated with a key in the entries collection and theEntryView.WriteEntryView
associated with that key in the cache- Returns:
- a
CompletableFuture
which will be completed when theBiConsumer
operation has been executed against all entries
-
evalMany
default <T> CompletableFuture<Void> evalMany(Map<? extends K, ? extends T> arguments, SerializableBiConsumer<T, EntryView.WriteEntryView<K, V>> f) Same asevalMany(Map, BiConsumer)
except that the function must also implementSerializable
The compiler will pick this overload for lambda parameters, making them
Serializable
-
evalMany
Evaluate a write-onlyConsumer
operation with theEntryView.WriteEntryView
of the value associated with the key, for each of the keys in the set passed in, and returns aCompletableFuture
that will be completed when the write-only operation has been executed against all the entries.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.
- Parameters:
keys
- the keys associated with each of theEntryView.WriteEntryView
passed in the function callbacksf
- operation that theEntryView.WriteEntryView
associated with one of the keys passed in- Returns:
- a
CompletableFuture
which will be completed when theConsumer
operation has been executed against all entries
-
evalMany
default CompletableFuture<Void> evalMany(Set<? extends K> keys, SerializableConsumer<EntryView.WriteEntryView<K, V>> f) Same asevalMany(Set, Consumer)
except that the function must also implementSerializable
The compiler will pick this overload for lambda parameters, making them
Serializable
-
evalAll
Evaluate a write-onlyConsumer
operation with theEntryView.WriteEntryView
of the value associated with the key, for all existing keys in functional map, and returns aCompletableFuture
that will be completed when the write-only operation has been executed against all the entries.- Parameters:
f
- operation that theEntryView.WriteEntryView
associated with one of the keys passed in- Returns:
- a
CompletableFuture
which will be completed when theConsumer
operation has been executed against all entries
-
evalAll
Same asevalAll(Consumer)
except that the function must also implementSerializable
The compiler will pick this overload for lambda parameters, making them
Serializable
-
truncate
CompletableFuture<Void> truncate()Truncate the contents of the cache, returning aCompletableFuture
that will be completed when the truncate process completes. This method can be used to implement:- Returns:
- a
CompletableFuture
that completes when the truncat has finished
-
listeners
Listeners.WriteListeners<K,V> listeners()Allows to write-only listeners to be registered.
-