public class TxLockedStreamImpl<K,V> extends LockedStreamImpl<K,V>
BaseCacheStream.SegmentCompletionListener
Constructor and Description |
---|
TxLockedStreamImpl(TransactionManager tm,
CacheStream<CacheEntry<K,V>> realStream,
long time,
TimeUnit unit) |
Modifier and Type | Method and Description |
---|---|
void |
forEach(BiConsumer<Cache<K,V>,? super CacheEntry<K,V>> biConsumer)
Performs an action for each element of this stream on the primary owner of the given key.
|
<R> Map<K,R> |
invokeAll(BiFunction<Cache<K,V>,? super CacheEntry<K,V>,R> biFunction)
Performs a BiFunction for each element of this stream on the primary owner of each entry returning
a value.
|
close, disableRehashAware, distributedBatchSize, filter, filterKeys, filterKeySegments, filterKeySegments, isParallel, iterator, onClose, parallel, parallelDistribution, segmentCompletionListener, sequential, sequentialDistribution, spliterator, timeout, unordered
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
filter, forEach, invokeAll
public TxLockedStreamImpl(TransactionManager tm, CacheStream<CacheEntry<K,V>> realStream, long time, TimeUnit unit)
public void forEach(BiConsumer<Cache<K,V>,? super CacheEntry<K,V>> biConsumer)
LockedStream
This method is performed while holding exclusive lock over the given entry and will be released
only after the consumer has completed. In the function, entry.setValue(newValue)
is equivalent to
cache.put(entry.getKey(), newValue)
.
If using pessimistic transactions this lock is not held using a transaction and thus the user can start a transaction in this consumer which also must be completed before returning. A transaction can be started in the consumer and if done it will share the same lock used to obtain the key.
Remember that if you are using an explicit transaction or an async method that these must be completed before the consumer returns to guarantee that they are operating within the scope of the lock for the given key. Failure to do so will lead into possible inconsistency as they will be performing operations without the proper locking.
Some methods on the provided cache may not work as expected. These include
Cache.putForExternalRead(Object, Object)
, AdvancedCache.lock(Object[])
,
AdvancedCache.lock(Collection)
, and AdvancedCache.removeGroup(String)
.
If these methods are used inside of the Consumer on the cache it will throw a IllegalStateException
.
This is due to possible interactions with locks while using these commands.
forEach
in interface LockedStream<K,V>
forEach
in class LockedStreamImpl<K,V>
biConsumer
- the biConsumer to run for each entry under their lockpublic <R> Map<K,R> invokeAll(BiFunction<Cache<K,V>,? super CacheEntry<K,V>,R> biFunction)
LockedStream
This method is currently marked as Experimental
since this method returns a Map and requires blocking.
This operation could take a deal of time and as such should be done using an asynchronous API. Most likely
this return type will be changed to use some sort of asynchronous return value. This method is here until
this can be implemented.
This BiFunction is invoked while holding an exclusive lock over the given entry that will be released
only after the function has completed. In the function, entry.setValue(newValue)
is equivalent to
cache.put(entry.getKey(), newValue)
.
If using pessimistic transactions this lock is not held using a transaction and thus the user can start a transaction in this consumer which also must be completed before returning. A transaction can be started in the biFunction and if done it will share the same lock used to obtain the key.
Remember if you are using an explicit transaction or an async method that these must be completed before the consumer returns to guarantee that they are operating within the scope of the lock for the given key. Failure to do so will lead into possible inconsistency as they will be performing operations without the proper locking.
Some methods on the provided cache may not work as expected. These include
Cache.putForExternalRead(Object, Object)
, AdvancedCache.lock(Object[])
,
AdvancedCache.lock(Collection)
, and AdvancedCache.removeGroup(String)
.
If these methods are used inside of the Consumer on the cache it will throw a IllegalStateException
.
This is due to possible interactions with locks while using these commands.
invokeAll
in interface LockedStream<K,V>
invokeAll
in class LockedStreamImpl<K,V>
R
- the return typebiFunction
- the biFunction to run for each entry under their lockCopyright © 2021 JBoss by Red Hat. All rights reserved.