Interface FunctionalMap.WriteOnlyMap<K,V>
-
- All Superinterfaces:
AutoCloseable
,FunctionalMap<K,V>
- Enclosing interface:
- FunctionalMap<K,V>
@Experimental public static interface FunctionalMap.WriteOnlyMap<K,V> extends FunctionalMap<K,V>
Exposes write-only operations that can be executed against the functional map. The write operations that can be applied per entry are exposed byEntryView.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
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description CompletableFuture<Void>
eval(K key, Consumer<EntryView.WriteEntryView<K,V>> f)
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.default CompletableFuture<Void>
eval(K key, org.infinispan.util.function.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, org.infinispan.util.function.SerializableBiConsumer<T,EntryView.WriteEntryView<K,V>> f)
Same aseval(Object, Object, BiConsumer)
except that the function must also implementSerializable
CompletableFuture<Void>
evalAll(Consumer<EntryView.WriteEntryView<K,V>> f)
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>
evalAll(org.infinispan.util.function.SerializableConsumer<EntryView.WriteEntryView<K,V>> f)
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, org.infinispan.util.function.SerializableBiConsumer<T,EntryView.WriteEntryView<K,V>> f)
Same asevalMany(Map, BiConsumer)
except that the function must also implementSerializable
CompletableFuture<Void>
evalMany(Set<? extends K> keys, Consumer<EntryView.WriteEntryView<K,V>> f)
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, org.infinispan.util.function.SerializableConsumer<EntryView.WriteEntryView<K,V>> f)
Same asevalMany(Set, Consumer)
except that the function must also implementSerializable
Listeners.WriteListeners<K,V>
listeners()
Allows to write-only listeners to be registered.CompletableFuture<Void>
truncate()
Truncate the contents of the cache, returning aCompletableFuture
that will be completed when the truncate process completes.FunctionalMap.WriteOnlyMap<K,V>
withParams(Param<?>... ps)
Tweak write-only functional map executions providingParam
instances.-
Methods inherited from interface org.infinispan.functional.FunctionalMap
getName, getStatus, isEncoded
-
-
-
-
Method Detail
-
withParams
FunctionalMap.WriteOnlyMap<K,V> withParams(Param<?>... ps)
Tweak write-only functional map executions providingParam
instances.- Specified by:
withParams
in interfaceFunctionalMap<K,V>
-
eval
<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.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 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 such asjavax.cache.Cache#put(Object, Object)
, 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, org.infinispan.util.function.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
CompletableFuture<Void> eval(K key, Consumer<EntryView.WriteEntryView<K,V>> f)
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
default CompletableFuture<Void> eval(K key, org.infinispan.util.function.SerializableConsumer<EntryView.WriteEntryView<K,V>> f)
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. 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.- 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, org.infinispan.util.function.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
CompletableFuture<Void> evalMany(Set<? extends K> keys, Consumer<EntryView.WriteEntryView<K,V>> f)
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.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.
- 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, org.infinispan.util.function.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
CompletableFuture<Void> evalAll(Consumer<EntryView.WriteEntryView<K,V>> f)
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.This method can be used to implement operations such as
javax.cache.Cache#removeAll()
.- 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
default CompletableFuture<Void> evalAll(org.infinispan.util.function.SerializableConsumer<EntryView.WriteEntryView<K,V>> f)
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:Map.clear()
javax.cache.Cache#clear()
- Returns:
- a
CompletableFuture
that completes when the truncat has finished
-
listeners
Listeners.WriteListeners<K,V> listeners()
Allows to write-only listeners to be registered.
-
-