Interface FunctionalMap.WriteOnlyMap<K,V>
-
- All Superinterfaces:
AutoCloseable,FunctionalMap<K,V>
- Enclosing interface:
- FunctionalMap<K,V>
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-onlyConsumeroperation with aEntryView.WriteEntryViewof the value associated with the key, and return aCompletableFuturewhich 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-onlyBiConsumeroperation, with an argument passed in and aEntryView.WriteEntryViewof the value associated with the key, and return aCompletableFuturewhich 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 implementSerializableCompletableFuture<Void>evalAll(Consumer<EntryView.WriteEntryView<K,V>> f)Evaluate a write-onlyConsumeroperation with theEntryView.WriteEntryViewof the value associated with the key, for all existing keys in functional map, and returns aCompletableFuturethat 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 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-onlyBiConsumeroperation, with an argument passed in and aEntryView.WriteEntryViewof the value associated with the key, for each of the keys in the set passed in, and returns aCompletableFuturethat 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 implementSerializableCompletableFuture<Void>evalMany(Set<? extends K> keys, Consumer<EntryView.WriteEntryView<K,V>> f)Evaluate a write-onlyConsumeroperation with theEntryView.WriteEntryViewof the value associated with the key, for each of the keys in the set passed in, and returns aCompletableFuturethat 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 implementSerializableListeners.WriteListeners<K,V>listeners()Allows to write-only listeners to be registered.CompletableFuture<Void>truncate()Truncate the contents of the cache, returning aCompletableFuturethat will be completed when the truncate process completes.FunctionalMap.WriteOnlyMap<K,V>withParams(Param<?>... ps)Tweak write-only functional map executions providingParaminstances.-
Methods inherited from interface java.lang.AutoCloseable
close
-
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 providingParaminstances.- Specified by:
withParamsin interfaceFunctionalMap<K,V>
-
eval
<T> CompletableFuture<Void> eval(K key, T argument, BiConsumer<T,EntryView.WriteEntryView<K,V>> f)
Evaluate a write-onlyBiConsumeroperation, with an argument passed in and aEntryView.WriteEntryViewof the value associated with the key, and return aCompletableFuturewhich 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 aBiConsumerthat 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, theBiConsumercould be cached and reused each time it's invoked.Note that when
encodersare 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.WriteEntryViewto be passed to the operationargument- argument passed in as first parameter to theBiConsumeroperation.f- operation that takes a user defined value, and aEntryView.WriteEntryViewassociated with the key, and writes to theEntryView.WriteEntryViewpassed in without returning anything- Returns:
- a
CompletableFuturewhich 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 implementSerializableThe 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-onlyConsumeroperation with aEntryView.WriteEntryViewof the value associated with the key, and return aCompletableFuturewhich 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.WriteEntryViewto be passed to the operationf- operation that takes aEntryView.WriteEntryViewassociated with the key and writes to the it without returning anything- Returns:
- a
CompletableFuturewhich will be completed when the operation completes
-
eval
default CompletableFuture<Void> eval(K key, SerializableConsumer<EntryView.WriteEntryView<K,V>> f)
Same aseval(Object, Consumer)except that the function must also implementSerializableThe 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-onlyBiConsumeroperation, with an argument passed in and aEntryView.WriteEntryViewof the value associated with the key, for each of the keys in the set passed in, and returns aCompletableFuturethat 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
encodersare 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.WriteEntryViewpassed in the function callbacksf- operation that consumes a value associated with a key in the entries collection and theEntryView.WriteEntryViewassociated with that key in the cache- Returns:
- a
CompletableFuturewhich will be completed when theBiConsumeroperation 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 implementSerializableThe 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-onlyConsumeroperation with theEntryView.WriteEntryViewof the value associated with the key, for each of the keys in the set passed in, and returns aCompletableFuturethat 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.WriteEntryViewpassed in the function callbacksf- operation that theEntryView.WriteEntryViewassociated with one of the keys passed in- Returns:
- a
CompletableFuturewhich will be completed when theConsumeroperation 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 implementSerializableThe compiler will pick this overload for lambda parameters, making them
Serializable
-
evalAll
CompletableFuture<Void> evalAll(Consumer<EntryView.WriteEntryView<K,V>> f)
Evaluate a write-onlyConsumeroperation with theEntryView.WriteEntryViewof the value associated with the key, for all existing keys in functional map, and returns aCompletableFuturethat 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.WriteEntryViewassociated with one of the keys passed in- Returns:
- a
CompletableFuturewhich will be completed when theConsumeroperation has been executed against all entries
-
evalAll
default CompletableFuture<Void> evalAll(SerializableConsumer<EntryView.WriteEntryView<K,V>> f)
Same asevalAll(Consumer)except that the function must also implementSerializableThe compiler will pick this overload for lambda parameters, making them
Serializable
-
truncate
CompletableFuture<Void> truncate()
Truncate the contents of the cache, returning aCompletableFuturethat will be completed when the truncate process completes. This method can be used to implement:Map.clear()javax.cache.Cache#clear()
- Returns:
- a
CompletableFuturethat completes when the truncat has finished
-
listeners
Listeners.WriteListeners<K,V> listeners()
Allows to write-only listeners to be registered.
-
-