Class TxLockedStreamImpl<K,V>
- java.lang.Object
-
- org.infinispan.stream.impl.LockedStreamImpl<K,V>
-
- org.infinispan.stream.impl.TxLockedStreamImpl<K,V>
-
- All Implemented Interfaces:
AutoCloseable
,BaseStream<CacheEntry<K,V>,LockedStream<K,V>>
,BaseCacheStream<CacheEntry<K,V>,LockedStream<K,V>>
,LockedStream<K,V>
public class TxLockedStreamImpl<K,V> extends LockedStreamImpl<K,V>
Locked Stream that is designed for transactions. This way it can suspend and resume the transaction upon invocation.- Since:
- 9.0
- Author:
- wburns
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.infinispan.BaseCacheStream
BaseCacheStream.SegmentCompletionListener
-
-
Constructor Summary
Constructors Constructor Description TxLockedStreamImpl(TransactionManager tm, CacheStream<CacheEntry<K,V>> realStream, long time, TimeUnit unit)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.-
Methods inherited from class org.infinispan.stream.impl.LockedStreamImpl
close, disableRehashAware, distributedBatchSize, filter, filterKeys, filterKeySegments, filterKeySegments, isParallel, iterator, onClose, parallel, parallelDistribution, segmentCompletionListener, sequential, sequentialDistribution, spliterator, timeout, unordered
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.infinispan.LockedStream
filter, forEach, invokeAll
-
-
-
-
Constructor Detail
-
TxLockedStreamImpl
public TxLockedStreamImpl(TransactionManager tm, CacheStream<CacheEntry<K,V>> realStream, long time, TimeUnit unit)
-
-
Method Detail
-
forEach
public void forEach(BiConsumer<Cache<K,V>,? super CacheEntry<K,V>> biConsumer)
Description copied from interface:LockedStream
Performs an action for each element of this stream on the primary owner of the given key.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 tocache.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)
, andAdvancedCache.removeGroup(String)
. If these methods are used inside of the Consumer on the cache it will throw aIllegalStateException
. This is due to possible interactions with locks while using these commands.- Specified by:
forEach
in interfaceLockedStream<K,V>
- Overrides:
forEach
in classLockedStreamImpl<K,V>
- Parameters:
biConsumer
- the biConsumer to run for each entry under their lock
-
invokeAll
public <R> Map<K,R> invokeAll(BiFunction<Cache<K,V>,? super CacheEntry<K,V>,R> biFunction)
Description copied from interface:LockedStream
Performs a BiFunction for each element of this stream on the primary owner of each entry returning a value. The returned value from the function will be sent back to the user mapped to the key that generated it, with all of these stored in a map. Both the BiFunction and the returned value must be Serializable in some way. This method will return only after all entries have been processed.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 tocache.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)
, andAdvancedCache.removeGroup(String)
. If these methods are used inside of the Consumer on the cache it will throw aIllegalStateException
. This is due to possible interactions with locks while using these commands.- Specified by:
invokeAll
in interfaceLockedStream<K,V>
- Overrides:
invokeAll
in classLockedStreamImpl<K,V>
- Type Parameters:
R
- the return type- Parameters:
biFunction
- the biFunction to run for each entry under their lock- Returns:
- a map with each key mapped to the value returned from the bi function
-
-