public interface LockedStream<K,V> extends BaseCacheStream<CacheEntry<K,V>,LockedStream<K,V>>
forEach(BiConsumer)
where the BiConsumer is invoked while guaranteeing that the entry being passed is properly locked for the
entire duration of the invocation.
An attempt is made to acquire the lock for an entry using the default
LockingConfiguration.lockAcquisitionTimeout()
before invoking any operations on it.
BaseCacheStream.SegmentCompletionListener
Modifier and Type | Method and Description |
---|---|
LockedStream<K,V> |
filter(Predicate<? super CacheEntry<K,V>> predicate)
Returns a locked stream consisting of the elements of this stream that match
the given predicate.
|
default LockedStream<K,V> |
filter(SerializablePredicate<? super CacheEntry<K,V>> predicate)
Same as
filter(Predicate) except that the Predicate must also
implement Serializable |
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.
|
default void |
forEach(SerializableBiConsumer<Cache<K,V>,? super CacheEntry<K,V>> biConsumer)
Same as
forEach(BiConsumer) except that the BiConsumer must also
implement Serializable |
Iterator<CacheEntry<K,V>> |
iterator()
This method is not supported when using a
LockedStream |
LockedStream |
segmentCompletionListener(BaseCacheStream.SegmentCompletionListener listener)
This method is not supported when using a
LockedStream |
Spliterator<CacheEntry<K,V>> |
spliterator()
This method is not supported when using a
LockedStream |
LockedStream |
timeout(long time,
TimeUnit unit)
Sets the timeout for the acquisition of the lock for each entry.
|
disableRehashAware, distributedBatchSize, filterKeys, filterKeySegments, parallelDistribution, sequentialDistribution
close, isParallel, onClose, parallel, sequential, unordered
LockedStream<K,V> filter(Predicate<? super CacheEntry<K,V>> predicate)
This filter is after the lock is acquired for the given key. This way the filter will see the same value as the consumer is given.
predicate
- predicatedefault LockedStream<K,V> filter(SerializablePredicate<? super CacheEntry<K,V>> predicate)
filter(Predicate)
except that the Predicate must also
implement Serializable
The compiler will pick this overload for lambda parameters, making them Serializable
predicate
- the predicate to filter out unwanted entriesvoid forEach(BiConsumer<Cache<K,V>,? super CacheEntry<K,V>> biConsumer)
This method is performed while holding exclusive lock over the given entry and will be released
only after the consumer has completed. If the entry is directly modified via the
Map.Entry.setValue(Object)
method this will be the same as if
Map.put(Object, Object)
was invoked.
If using a pessimistic transaction 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 transactions while using these commands.
biConsumer
- the biConsumer to run for each entry under their lockdefault void forEach(SerializableBiConsumer<Cache<K,V>,? super CacheEntry<K,V>> biConsumer)
forEach(BiConsumer)
except that the BiConsumer must also
implement Serializable
The compiler will pick this overload for lambda parameters, making them Serializable
biConsumer
- the biConsumer to run for each entry under their lockLockedStream timeout(long time, TimeUnit unit)
timeout
in interface BaseCacheStream<CacheEntry<K,V>,LockedStream<K,V>>
time
- the maximum time to waitunit
- the time unit of the timeout argumentLockedStream segmentCompletionListener(BaseCacheStream.SegmentCompletionListener listener) throws UnsupportedOperationException
LockedStream
segmentCompletionListener
in interface BaseCacheStream<CacheEntry<K,V>,LockedStream<K,V>>
listener
- The listener that will be called back as segments are completed.UnsupportedOperationException
Iterator<CacheEntry<K,V>> iterator() throws UnsupportedOperationException
LockedStream
iterator
in interface BaseStream<CacheEntry<K,V>,LockedStream<K,V>>
UnsupportedOperationException
Spliterator<CacheEntry<K,V>> spliterator() throws UnsupportedOperationException
LockedStream
spliterator
in interface BaseStream<CacheEntry<K,V>,LockedStream<K,V>>
UnsupportedOperationException
Copyright © 2018 JBoss, a division of Red Hat. All rights reserved.