public final class WriteOnlyMapImpl<K,V> extends Object implements FunctionalMap.WriteOnlyMap<K,V>
FunctionalMap.ReadOnlyMap<K,V>, FunctionalMap.ReadWriteMap<K,V>, FunctionalMap.WriteOnlyMap<K,V>
Modifier and Type | Field and Description |
---|---|
protected FunctionalMapImpl<K,V> |
fmap |
Modifier and Type | Method and Description |
---|---|
void |
close() |
static <K,V> FunctionalMap.WriteOnlyMap<K,V> |
create(FunctionalMapImpl<K,V> functionalMap) |
CompletableFuture<Void> |
eval(K key,
Consumer<EntryView.WriteEntryView<V>> f)
Evaluate a write-only
Consumer operation with a
EntryView.WriteEntryView of the value associated with the key,
and return a CompletableFuture which will be
completed with the object returned by the operation. |
CompletableFuture<Void> |
eval(K key,
V value,
BiConsumer<V,EntryView.WriteEntryView<V>> f)
Evaluate a write-only
BiConsumer operation, with a value
passed in and a EntryView.WriteEntryView of the value associated with
the key, and return a CompletableFuture which will be
completed when the operation completes. |
CompletableFuture<Void> |
evalAll(Consumer<EntryView.WriteEntryView<V>> f)
Evaluate a write-only
Consumer operation with the
EntryView.WriteEntryView of the value associated with the key, for all
existing keys in functional map, and returns a CompletableFuture
that will be completed when the write-only operation has been executed
against all the entries. |
CompletableFuture<Void> |
evalMany(Map<? extends K,? extends V> entries,
BiConsumer<V,EntryView.WriteEntryView<V>> f)
Evaluate a write-only
BiConsumer operation, with a value
passed in and a EntryView.WriteEntryView of the value associated with
the key, for each of the keys in the set passed in, and returns a
CompletableFuture 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<V>> f)
Evaluate a write-only
Consumer operation with the
EntryView.WriteEntryView of the value associated with the key, for each
of the keys in the set passed in, and returns a
CompletableFuture that will be completed when the write-only
operation has been executed against all the entries. |
String |
getName()
Functional map's name.
|
Status |
getStatus()
Functional map's status.
|
Listeners.WriteListeners<K,V> |
listeners()
Allows to write-only listeners to be registered.
|
CompletableFuture<Void> |
truncate()
Truncate the contents of the cache, returning a
CompletableFuture
that will be completed when the truncate process completes. |
FunctionalMap.WriteOnlyMap<K,V> |
withParams(Param<?>... ps)
Tweak write-only functional map executions providing
Param instances. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getName, getStatus
close
protected final FunctionalMapImpl<K,V> fmap
public static <K,V> FunctionalMap.WriteOnlyMap<K,V> create(FunctionalMapImpl<K,V> functionalMap)
public CompletableFuture<Void> eval(K key, Consumer<EntryView.WriteEntryView<V>> f)
FunctionalMap.WriteOnlyMap
Consumer
operation with a
EntryView.WriteEntryView
of the value associated with the key,
and return a CompletableFuture
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.
eval
in interface FunctionalMap.WriteOnlyMap<K,V>
key
- the key associated with the EntryView.WriteEntryView
to be
passed to the operationf
- operation that takes a EntryView.WriteEntryView
associated with
the key and writes to the it without returning anythingCompletableFuture
which will be completed when the
operation completespublic CompletableFuture<Void> eval(K key, V value, BiConsumer<V,EntryView.WriteEntryView<V>> f)
FunctionalMap.WriteOnlyMap
BiConsumer
operation, with a value
passed in and a EntryView.WriteEntryView
of the value associated with
the key, and return a CompletableFuture
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 with FunctionalMap.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 a BiConsumer
that
takes user provided value as first parameter, the operation does not
capture any external objects when implementing simple operations
such as javax.cache.Cache#put(Object, Object)
, and hence, the
BiConsumer
could be cached and reused each time it's invoked.
eval
in interface FunctionalMap.WriteOnlyMap<K,V>
key
- the key associated with the EntryView.WriteEntryView
to be
passed to the operationvalue
- value to write, passed in as first parameter to the
BiConsumer
operation.f
- operation that takes a user defined value, and a
EntryView.WriteEntryView
associated with the key, and writes
to the EntryView.WriteEntryView
passed in without returning anythingCompletableFuture
which will be completed when the
operation completespublic CompletableFuture<Void> evalMany(Map<? extends K,? extends V> entries, BiConsumer<V,EntryView.WriteEntryView<V>> f)
FunctionalMap.WriteOnlyMap
BiConsumer
operation, with a value
passed in and a EntryView.WriteEntryView
of the value associated with
the key, for each of the keys in the set passed in, and returns a
CompletableFuture
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.
evalMany
in interface FunctionalMap.WriteOnlyMap<K,V>
entries
- the key/value pairs associated with each of the
EntryView.WriteEntryView
passed in the function callbacksf
- operation that consumes a value associated with a key in the
entries collection and the EntryView.WriteEntryView
associated
with that key in the cacheCompletableFuture
which will be completed when
the BiConsumer
operation has been executed against
all entriespublic CompletableFuture<Void> evalMany(Set<? extends K> keys, Consumer<EntryView.WriteEntryView<V>> f)
FunctionalMap.WriteOnlyMap
Consumer
operation with the
EntryView.WriteEntryView
of the value associated with the key, for each
of the keys in the set passed in, and returns a
CompletableFuture
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.
evalMany
in interface FunctionalMap.WriteOnlyMap<K,V>
keys
- the keys associated with each of the EntryView.WriteEntryView
passed in the function callbacksf
- operation that the EntryView.WriteEntryView
associated with
one of the keys passed inCompletableFuture
which will be completed when
the Consumer
operation has been executed against all
entriespublic CompletableFuture<Void> evalAll(Consumer<EntryView.WriteEntryView<V>> f)
FunctionalMap.WriteOnlyMap
Consumer
operation with the
EntryView.WriteEntryView
of the value associated with the key, for all
existing keys in functional map, and returns a CompletableFuture
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()
.
evalAll
in interface FunctionalMap.WriteOnlyMap<K,V>
f
- operation that the EntryView.WriteEntryView
associated with
one of the keys passed inCompletableFuture
which will be completed when
the Consumer
operation has been executed against all
entriespublic CompletableFuture<Void> truncate()
FunctionalMap.WriteOnlyMap
CompletableFuture
that will be completed when the truncate process completes.
This method can be used to implement:
Map.clear()
javax.cache.Cache#clear()
truncate
in interface FunctionalMap.WriteOnlyMap<K,V>
CompletableFuture
that completes when the truncat
has finishedpublic FunctionalMap.WriteOnlyMap<K,V> withParams(Param<?>... ps)
FunctionalMap.WriteOnlyMap
Param
instances.withParams
in interface FunctionalMap<K,V>
withParams
in interface FunctionalMap.WriteOnlyMap<K,V>
public Listeners.WriteListeners<K,V> listeners()
FunctionalMap.WriteOnlyMap
listeners
in interface FunctionalMap.WriteOnlyMap<K,V>
public String getName()
FunctionalMap
getName
in interface FunctionalMap<K,V>
public Status getStatus()
FunctionalMap
getStatus
in interface FunctionalMap<K,V>
public void close() throws Exception
close
in interface AutoCloseable
Exception
Copyright © 2020 JBoss, a division of Red Hat. All rights reserved.