Class WriteOnlyMapImpl<K,V>
- java.lang.Object
-
- org.infinispan.functional.impl.WriteOnlyMapImpl<K,V>
-
- All Implemented Interfaces:
AutoCloseable
,FunctionalMap<K,V>
,FunctionalMap.WriteOnlyMap<K,V>
public final class WriteOnlyMapImpl<K,V> extends Object implements FunctionalMap.WriteOnlyMap<K,V>
Write-only map implementation.- 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
Fields Modifier and Type Field Description protected FunctionalMapImpl<K,V>
fmap
protected DataConversion
keyDataConversion
protected Params
params
protected DataConversion
valueDataConversion
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
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)
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.<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.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.<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.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.protected InvocationContext
getInvocationContext(boolean isWrite, int keyCount)
String
getName()
Functional map's name.ComponentStatus
getStatus()
Functional map's status.protected <T> CompletableFuture<T>
invokeAsync(InvocationContext ctx, VisitableCommand cmd)
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 class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.AutoCloseable
close
-
Methods inherited from interface org.infinispan.functional.FunctionalMap
getName, getStatus, isEncoded
-
-
-
-
Field Detail
-
fmap
protected final FunctionalMapImpl<K,V> fmap
-
params
protected final Params params
-
keyDataConversion
protected final DataConversion keyDataConversion
-
valueDataConversion
protected final DataConversion valueDataConversion
-
-
Method Detail
-
create
public static <K,V> FunctionalMap.WriteOnlyMap<K,V> create(FunctionalMapImpl<K,V> functionalMap)
-
eval
public CompletableFuture<Void> eval(K key, Consumer<EntryView.WriteEntryView<K,V>> f)
Description copied from interface:FunctionalMap.WriteOnlyMap
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.
- Specified by:
eval
in interfaceFunctionalMap.WriteOnlyMap<K,V>
- 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
public <T> CompletableFuture<Void> eval(K key, T argument, BiConsumer<T,EntryView.WriteEntryView<K,V>> f)
Description copied from interface:FunctionalMap.WriteOnlyMap
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
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 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.- Specified by:
eval
in interfaceFunctionalMap.WriteOnlyMap<K,V>
- 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
-
evalMany
public <T> CompletableFuture<Void> evalMany(Map<? extends K,? extends T> arguments, BiConsumer<T,EntryView.WriteEntryView<K,V>> f)
Description copied from interface:FunctionalMap.WriteOnlyMap
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.- Specified by:
evalMany
in interfaceFunctionalMap.WriteOnlyMap<K,V>
- 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
public CompletableFuture<Void> evalMany(Set<? extends K> keys, Consumer<EntryView.WriteEntryView<K,V>> f)
Description copied from interface:FunctionalMap.WriteOnlyMap
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.
- Specified by:
evalMany
in interfaceFunctionalMap.WriteOnlyMap<K,V>
- 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
-
evalAll
public CompletableFuture<Void> evalAll(Consumer<EntryView.WriteEntryView<K,V>> f)
Description copied from interface:FunctionalMap.WriteOnlyMap
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()
.- Specified by:
evalAll
in interfaceFunctionalMap.WriteOnlyMap<K,V>
- 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
-
truncate
public CompletableFuture<Void> truncate()
Description copied from interface:FunctionalMap.WriteOnlyMap
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()
- Specified by:
truncate
in interfaceFunctionalMap.WriteOnlyMap<K,V>
- Returns:
- a
CompletableFuture
that completes when the truncat has finished
-
withParams
public FunctionalMap.WriteOnlyMap<K,V> withParams(Param<?>... ps)
Description copied from interface:FunctionalMap.WriteOnlyMap
Tweak write-only functional map executions providingParam
instances.- Specified by:
withParams
in interfaceFunctionalMap<K,V>
- Specified by:
withParams
in interfaceFunctionalMap.WriteOnlyMap<K,V>
-
listeners
public Listeners.WriteListeners<K,V> listeners()
Description copied from interface:FunctionalMap.WriteOnlyMap
Allows to write-only listeners to be registered.- Specified by:
listeners
in interfaceFunctionalMap.WriteOnlyMap<K,V>
-
getName
public String getName()
Description copied from interface:FunctionalMap
Functional map's name.- Specified by:
getName
in interfaceFunctionalMap<K,V>
-
getStatus
public ComponentStatus getStatus()
Description copied from interface:FunctionalMap
Functional map's status.- Specified by:
getStatus
in interfaceFunctionalMap<K,V>
-
close
public void close() throws Exception
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
getInvocationContext
protected InvocationContext getInvocationContext(boolean isWrite, int keyCount)
-
invokeAsync
protected <T> CompletableFuture<T> invokeAsync(InvocationContext ctx, VisitableCommand cmd)
-
-