Class WriteOnlyMapImpl<K,V>
- All Implemented Interfaces:
AutoCloseable,FunctionalMap<K,,V> FunctionalMap.WriteOnlyMap<K,V>
- 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> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final FunctionalMapImpl<K,V> protected final DataConversionprotected final Paramsprotected final DataConversion -
Method Summary
Modifier and TypeMethodDescriptioncache()voidclose()static <K,V> FunctionalMap.WriteOnlyMap<K, V> create(FunctionalMapImpl<K, V> functionalMap) protected Map<?,?> encodeEntries(Map<? extends K, ?> entries) protected Set<?>encodeKeys(Set<? extends K> keys) 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.<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.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.<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.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.protected InvocationContextgetInvocationContext(boolean isWrite, int keyCount) getName()Functional map's name.Functional map's status.protected <T> CompletableFuture<T>invokeAsync(InvocationContext ctx, VisitableCommand cmd) Allows to write-only listeners to be registered.truncate()Truncate the contents of the cache, returning aCompletableFuturethat will be completed when the truncate process completes.withParams(Param<?>... ps) Tweak write-only functional map executions providingParaminstances.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.AutoCloseable
closeMethods inherited from interface org.infinispan.functional.FunctionalMap
cache, getName, getStatus, isEncoded
-
Field Details
-
fmap
-
params
-
keyDataConversion
-
valueDataConversion
-
-
Method Details
-
create
-
eval
Description copied from interface:FunctionalMap.WriteOnlyMapEvaluate 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.
- Specified by:
evalin interfaceFunctionalMap.WriteOnlyMap<K,V> - 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
public <T> CompletableFuture<Void> eval(K key, T argument, BiConsumer<T, EntryView.WriteEntryView<K, V>> f) Description copied from interface:FunctionalMap.WriteOnlyMapEvaluate 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
FunctionalMap.WriteOnlyMap.eval(Object, Consumer)and in fact, the functionality provided by this function could indeed be implemented withFunctionalMap.WriteOnlyMap.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,FunctionalMap.WriteOnlyMap.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.- Specified by:
evalin interfaceFunctionalMap.WriteOnlyMap<K,V> - 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
-
evalMany
public <T> CompletableFuture<Void> evalMany(Map<? extends K, ? extends T> arguments, BiConsumer<T, EntryView.WriteEntryView<K, V>> f) Description copied from interface:FunctionalMap.WriteOnlyMapEvaluate 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.- Specified by:
evalManyin interfaceFunctionalMap.WriteOnlyMap<K,V> - 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
public CompletableFuture<Void> evalMany(Set<? extends K> keys, Consumer<EntryView.WriteEntryView<K, V>> f) Description copied from interface:FunctionalMap.WriteOnlyMapEvaluate 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.
- Specified by:
evalManyin interfaceFunctionalMap.WriteOnlyMap<K,V> - 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
-
evalAll
Description copied from interface:FunctionalMap.WriteOnlyMapEvaluate 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().- Specified by:
evalAllin interfaceFunctionalMap.WriteOnlyMap<K,V> - 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
-
truncate
Description copied from interface:FunctionalMap.WriteOnlyMapTruncate 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()
- Specified by:
truncatein interfaceFunctionalMap.WriteOnlyMap<K,V> - Returns:
- a
CompletableFuturethat completes when the truncat has finished
-
withParams
Description copied from interface:FunctionalMap.WriteOnlyMapTweak write-only functional map executions providingParaminstances.- Specified by:
withParamsin interfaceFunctionalMap<K,V> - Specified by:
withParamsin interfaceFunctionalMap.WriteOnlyMap<K,V>
-
listeners
Description copied from interface:FunctionalMap.WriteOnlyMapAllows to write-only listeners to be registered.- Specified by:
listenersin interfaceFunctionalMap.WriteOnlyMap<K,V>
-
getName
Description copied from interface:FunctionalMapFunctional map's name.- Specified by:
getNamein interfaceFunctionalMap<K,V>
-
getStatus
Description copied from interface:FunctionalMapFunctional map's status.- Specified by:
getStatusin interfaceFunctionalMap<K,V>
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
cache
- Specified by:
cachein interfaceFunctionalMap<K,V>
-
getInvocationContext
-
invokeAsync
-
encodeKeys
-
encodeEntries
-