Class DistributedIntCacheStream<Original>
- java.lang.Object
-
- org.infinispan.stream.impl.AbstractCacheStream<Original,Integer,IntStream,IntCacheStream>
-
- org.infinispan.stream.impl.DistributedIntCacheStream<Original>
-
- Type Parameters:
Original- original stream type
- All Implemented Interfaces:
AutoCloseable,BaseStream<Integer,IntStream>,IntStream,BaseCacheStream<Integer,IntStream>,IntCacheStream
public class DistributedIntCacheStream<Original> extends AbstractCacheStream<Original,Integer,IntStream,IntCacheStream> implements IntCacheStream
Implementation ofIntStreamthat utilizes a lazily evaluated distributed back end execution. Note this class is only able to be created usingCacheStream.mapToInt(ToIntFunction)or similar methods from theCacheStreaminterface.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.infinispan.BaseCacheStream
BaseCacheStream.SegmentCompletionListener
-
Nested classes/interfaces inherited from interface java.util.stream.IntStream
IntStream.Builder
-
-
Field Summary
-
Fields inherited from class org.infinispan.stream.impl.AbstractCacheStream
closeRunnable, cpm, distributedBatchSize, dm, executor, includeLoader, intermediateOperations, invocationContext, iteratorOperation, keyPartitioner, keysToFilter, localAddress, parallel, parallelDistribution, partition, registry, rehashAware, segmentCompletionListener, segmentsToFilter, stateTransferLock, supplier, timeout, timeoutUnit, toKeyFunction
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedDistributedIntCacheStream(AbstractCacheStream other)This constructor is to be used only when a user calls a map or flat map method changing to an IntStream from a CacheStream, Stream, DoubleStream, LongStream etc.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanallMatch(IntPredicate predicate)booleananyMatch(IntPredicate predicate)DoubleCacheStreamasDoubleStream()LongCacheStreamasLongStream()OptionalDoubleaverage()CacheStream<Integer>boxed()protected <R> DistributedCacheStream<Original,R>cacheStream()<R> Rcollect(Supplier<R> supplier, ObjIntConsumer<R> accumulator, BiConsumer<R,R> combiner)longcount()IntCacheStreamdisableRehashAware()Disables tracking of rehash events that could occur to the underlying cache.IntCacheStreamdistinct()IntCacheStreamdistributedBatchSize(int batchSize)Controls how many keys are returned from a remote node when using a stream terminal operation with a distributed cache to back this stream.protected DistributedDoubleCacheStream<Original>doubleCacheStream()IntCacheStreamfilter(IntPredicate predicate)IntCacheStreamfilter(SerializableIntPredicate predicate)Same asIntCacheStream.filter(IntPredicate)except that the IntPredicate must also implementSerializableIntCacheStreamfilterKeys(Set<?> keys)Filters which entries are returned by only returning ones that map to the given key.IntCacheStreamfilterKeySegments(Set<Integer> segments)Filters which entries are returned by what segment they are present in.IntCacheStreamfilterKeySegments(org.infinispan.commons.util.IntSet segments)Filters which entries are returned by what segment they are present in.OptionalIntfindAny()OptionalIntfindFirst()IntCacheStreamflatMap(IntFunction<? extends IntStream> mapper)IntCacheStreamflatMap(SerializableIntFunction<? extends IntStream> mapper)Same asIntCacheStream.flatMap(IntFunction)except that the IntFunction must also implementSerializablevoidforEach(IntConsumer action)<K,V>
voidforEach(ObjIntConsumer<Cache<K,V>> action)Same asIntStream.forEach(IntConsumer)except that it takes anObjIntConsumerthat provides access to the underlyingCachethat is backing this stream.voidforEach(SerializableIntConsumer action)Same asIntStream.forEach(IntConsumer)except that the IntConsumer must also implementSerializable<K,V>
voidforEach(SerializableObjIntConsumer<Cache<K,V>> action)Same asIntCacheStream.forEach(ObjIntConsumer)except that theBiConsumermust also implementSerializablevoidforEachOrdered(IntConsumer action)protected LoggetLog()PrimitiveIterator.OfIntiterator()IntCacheStreamlimit(long maxSize)protected DistributedLongCacheStream<Original>longCacheStream()IntCacheStreammap(IntUnaryOperator mapper)IntCacheStreammap(SerializableIntUnaryOperator mapper)Same asIntCacheStream.map(IntUnaryOperator)except that the IntUnaryOperator must also implementSerializableDoubleCacheStreammapToDouble(IntToDoubleFunction mapper)DoubleCacheStreammapToDouble(SerializableIntToDoubleFunction mapper)Same asIntCacheStream.mapToDouble(IntToDoubleFunction)except that the IntToIntFunction must also implementSerializableLongCacheStreammapToLong(IntToLongFunction mapper)LongCacheStreammapToLong(SerializableIntToLongFunction mapper)Same asIntCacheStream.mapToLong(IntToLongFunction)except that the IntToLongFunction must also implementSerializable<U> CacheStream<U>mapToObj(IntFunction<? extends U> mapper)<U> CacheStream<U>mapToObj(SerializableIntFunction<? extends U> mapper)Same asIntCacheStream.mapToObj(IntFunction)except that the IntFunction must also implementSerializableOptionalIntmax()OptionalIntmin()booleannoneMatch(IntPredicate predicate)IntCacheStreamparallelDistribution()This would enable sending requests to all other remote nodes when a terminal operator is performed.IntCacheStreampeek(IntConsumer action)IntCacheStreampeek(SerializableIntConsumer action)Same asIntCacheStream.flatMap(IntFunction)except that the IntFunction must also implementSerializableintreduce(int identity, IntBinaryOperator op)OptionalIntreduce(IntBinaryOperator op)IntCacheStreamsegmentCompletionListener(BaseCacheStream.SegmentCompletionListener listener)Allows registration of a segment completion listener that is notified when a segment has completed processing.IntCacheStreamsequentialDistribution()This would disable sending requests to all other remote nodes compared to one at a time.IntCacheStreamskip(long n)IntCacheStreamsorted()Spliterator.OfIntspliterator()intsum()IntSummaryStatisticssummaryStatistics()IntCacheStreamtimeout(long timeout, TimeUnit unit)Sets a given time to wait for a remote operation to respond by.int[]toArray()protected DistributedIntCacheStreamunwrap()-
Methods inherited from class org.infinispan.stream.impl.AbstractCacheStream
addIntermediateOperation, addIntermediateOperation, addIntermediateOperationMap, close, composeWithExceptions, isParallel, isPrimaryOwner, onClose, parallel, sequential, unordered
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.stream.BaseStream
close, isParallel
-
-
-
-
Constructor Detail
-
DistributedIntCacheStream
protected DistributedIntCacheStream(AbstractCacheStream other)
This constructor is to be used only when a user calls a map or flat map method changing to an IntStream from a CacheStream, Stream, DoubleStream, LongStream etc.- Parameters:
other- other instance ofAbstractCacheStreamto copy details from
-
-
Method Detail
-
getLog
protected Log getLog()
- Specified by:
getLogin classAbstractCacheStream<Original,Integer,IntStream,IntCacheStream>
-
unwrap
protected DistributedIntCacheStream unwrap()
- Specified by:
unwrapin classAbstractCacheStream<Original,Integer,IntStream,IntCacheStream>
-
filter
public IntCacheStream filter(IntPredicate predicate)
Description copied from interface:IntCacheStream- Specified by:
filterin interfaceIntCacheStream- Specified by:
filterin interfaceIntStream- Returns:
- the new cache int stream
-
filter
public IntCacheStream filter(SerializableIntPredicate predicate)
Description copied from interface:IntCacheStreamSame asIntCacheStream.filter(IntPredicate)except that the IntPredicate must also implementSerializableThe compiler will pick this overload for lambda parameters, making them
Serializable- Specified by:
filterin interfaceIntCacheStream- Parameters:
predicate- a non-interfering, stateless predicate to apply to each element to determine if it should be included- Returns:
- the new cache int stream
-
map
public IntCacheStream map(IntUnaryOperator mapper)
Description copied from interface:IntCacheStream- Specified by:
mapin interfaceIntCacheStream- Specified by:
mapin interfaceIntStream- Returns:
- the new cache int stream
-
map
public IntCacheStream map(SerializableIntUnaryOperator mapper)
Description copied from interface:IntCacheStreamSame asIntCacheStream.map(IntUnaryOperator)except that the IntUnaryOperator must also implementSerializableThe compiler will pick this overload for lambda parameters, making them
Serializable- Specified by:
mapin interfaceIntCacheStream- Parameters:
mapper- a non-interfering, stateless function to apply to each element- Returns:
- the new cache int stream
-
mapToObj
public <U> CacheStream<U> mapToObj(IntFunction<? extends U> mapper)
Description copied from interface:IntCacheStream- Specified by:
mapToObjin interfaceIntCacheStream- Specified by:
mapToObjin interfaceIntStream- Returns:
- the new cache stream
-
mapToObj
public <U> CacheStream<U> mapToObj(SerializableIntFunction<? extends U> mapper)
Description copied from interface:IntCacheStreamSame asIntCacheStream.mapToObj(IntFunction)except that the IntFunction must also implementSerializableThe compiler will pick this overload for lambda parameters, making them
Serializable- Specified by:
mapToObjin interfaceIntCacheStream- Type Parameters:
U- the element type of the new stream- Parameters:
mapper- a non-interfering, stateless function to apply to each element- Returns:
- the new cache stream
-
mapToLong
public LongCacheStream mapToLong(IntToLongFunction mapper)
Description copied from interface:IntCacheStream- Specified by:
mapToLongin interfaceIntCacheStream- Specified by:
mapToLongin interfaceIntStream- Returns:
- the new cache long stream
-
mapToLong
public LongCacheStream mapToLong(SerializableIntToLongFunction mapper)
Description copied from interface:IntCacheStreamSame asIntCacheStream.mapToLong(IntToLongFunction)except that the IntToLongFunction must also implementSerializableThe compiler will pick this overload for lambda parameters, making them
Serializable- Specified by:
mapToLongin interfaceIntCacheStream- Parameters:
mapper- a non-interfering, stateless function to apply to each element- Returns:
- the new cache long stream
-
mapToDouble
public DoubleCacheStream mapToDouble(IntToDoubleFunction mapper)
Description copied from interface:IntCacheStream- Specified by:
mapToDoublein interfaceIntCacheStream- Specified by:
mapToDoublein interfaceIntStream- Returns:
- the new cache double stream
-
mapToDouble
public DoubleCacheStream mapToDouble(SerializableIntToDoubleFunction mapper)
Description copied from interface:IntCacheStreamSame asIntCacheStream.mapToDouble(IntToDoubleFunction)except that the IntToIntFunction must also implementSerializableThe compiler will pick this overload for lambda parameters, making them
Serializable- Specified by:
mapToDoublein interfaceIntCacheStream- Parameters:
mapper- a non-interfering, stateless function to apply to each element- Returns:
- the new cache double stream
-
flatMap
public IntCacheStream flatMap(IntFunction<? extends IntStream> mapper)
Description copied from interface:IntCacheStream- Specified by:
flatMapin interfaceIntCacheStream- Specified by:
flatMapin interfaceIntStream- Returns:
- the new cache int stream
-
flatMap
public IntCacheStream flatMap(SerializableIntFunction<? extends IntStream> mapper)
Description copied from interface:IntCacheStreamSame asIntCacheStream.flatMap(IntFunction)except that the IntFunction must also implementSerializableThe compiler will pick this overload for lambda parameters, making them
Serializable- Specified by:
flatMapin interfaceIntCacheStream- Parameters:
mapper- a non-interfering, stateless function to apply to each element which produces aIntStreamof new values- Returns:
- the new cache int stream
-
distinct
public IntCacheStream distinct()
Description copied from interface:IntCacheStream- Specified by:
distinctin interfaceIntCacheStream- Specified by:
distinctin interfaceIntStream- Returns:
- the new cache int stream
-
sorted
public IntCacheStream sorted()
Description copied from interface:IntCacheStream- Specified by:
sortedin interfaceIntCacheStream- Specified by:
sortedin interfaceIntStream- Returns:
- the new cache int stream
-
peek
public IntCacheStream peek(IntConsumer action)
Description copied from interface:IntCacheStream- Specified by:
peekin interfaceIntCacheStream- Specified by:
peekin interfaceIntStream- Returns:
- the new cache int stream
-
peek
public IntCacheStream peek(SerializableIntConsumer action)
Description copied from interface:IntCacheStreamSame asIntCacheStream.flatMap(IntFunction)except that the IntFunction must also implementSerializableThe compiler will pick this overload for lambda parameters, making them
Serializable- Specified by:
peekin interfaceIntCacheStream- Parameters:
action- a non-interfering action to perform on the elements as they are consumed from the stream- Returns:
- the new cache int stream
-
limit
public IntCacheStream limit(long maxSize)
Description copied from interface:IntCacheStream- Specified by:
limitin interfaceIntCacheStream- Specified by:
limitin interfaceIntStream- Returns:
- the new cache int stream
-
skip
public IntCacheStream skip(long n)
Description copied from interface:IntCacheStream- Specified by:
skipin interfaceIntCacheStream- Specified by:
skipin interfaceIntStream- Returns:
- the new cache int stream
-
asLongStream
public LongCacheStream asLongStream()
Description copied from interface:IntCacheStream- Specified by:
asLongStreamin interfaceIntCacheStream- Specified by:
asLongStreamin interfaceIntStream- Returns:
- the cache long stream
-
asDoubleStream
public DoubleCacheStream asDoubleStream()
Description copied from interface:IntCacheStream- Specified by:
asDoubleStreamin interfaceIntCacheStream- Specified by:
asDoubleStreamin interfaceIntStream- Returns:
- the cache double stream
-
boxed
public CacheStream<Integer> boxed()
Description copied from interface:IntCacheStream- Specified by:
boxedin interfaceIntCacheStream- Specified by:
boxedin interfaceIntStream- Returns:
- the new cache stream containing integers
-
forEach
public void forEach(IntConsumer action)
-
forEach
public void forEach(SerializableIntConsumer action)
Description copied from interface:IntCacheStreamSame asIntStream.forEach(IntConsumer)except that the IntConsumer must also implementSerializableThe compiler will pick this overload for lambda parameters, making them
Serializable- Specified by:
forEachin interfaceIntCacheStream- Parameters:
action- a non-interfering action to perform on the elements
-
forEach
public <K,V> void forEach(ObjIntConsumer<Cache<K,V>> action)
Description copied from interface:IntCacheStreamSame asIntStream.forEach(IntConsumer)except that it takes anObjIntConsumerthat provides access to the underlyingCachethat is backing this stream.Note that the
CacheAwareinterface is not supported for injection using this method as the cache is provided in the consumer directly.- Specified by:
forEachin interfaceIntCacheStream- Type Parameters:
K- key type of the cacheV- value type of the cache- Parameters:
action- consumer to be ran for each element in the stream
-
forEach
public <K,V> void forEach(SerializableObjIntConsumer<Cache<K,V>> action)
Description copied from interface:IntCacheStreamSame asIntCacheStream.forEach(ObjIntConsumer)except that theBiConsumermust also implementSerializable- Specified by:
forEachin interfaceIntCacheStream- Type Parameters:
K- key type of the cacheV- value type of the cache- Parameters:
action- consumer to be ran for each element in the stream
-
forEachOrdered
public void forEachOrdered(IntConsumer action)
- Specified by:
forEachOrderedin interfaceIntStream
-
reduce
public int reduce(int identity, IntBinaryOperator op)
-
reduce
public OptionalInt reduce(IntBinaryOperator op)
-
collect
public <R> R collect(Supplier<R> supplier, ObjIntConsumer<R> accumulator, BiConsumer<R,R> combiner)
-
min
public OptionalInt min()
-
max
public OptionalInt max()
-
average
public OptionalDouble average()
-
summaryStatistics
public IntSummaryStatistics summaryStatistics()
- Specified by:
summaryStatisticsin interfaceIntStream
-
anyMatch
public boolean anyMatch(IntPredicate predicate)
-
allMatch
public boolean allMatch(IntPredicate predicate)
-
noneMatch
public boolean noneMatch(IntPredicate predicate)
-
findFirst
public OptionalInt findFirst()
-
findAny
public OptionalInt findAny()
-
iterator
public PrimitiveIterator.OfInt iterator()
-
spliterator
public Spliterator.OfInt spliterator()
- Specified by:
spliteratorin interfaceBaseStream<Integer,IntStream>- Specified by:
spliteratorin interfaceIntStream
-
sequentialDistribution
public IntCacheStream sequentialDistribution()
Description copied from interface:IntCacheStreamThis would disable sending requests to all other remote nodes compared to one at a time. This can reduce memory pressure on the originator node at the cost of performance.Parallel distribution is enabled by default except for
CacheStream.iterator()andCacheStream.spliterator()- Specified by:
sequentialDistributionin interfaceBaseCacheStream<Integer,IntStream>- Specified by:
sequentialDistributionin interfaceIntCacheStream- Returns:
- a stream with parallel distribution disabled.
-
parallelDistribution
public IntCacheStream parallelDistribution()
Description copied from interface:BaseCacheStreamThis would enable sending requests to all other remote nodes when a terminal operator is performed. This requires additional overhead as it must process results concurrently from various nodes, but should perform faster in the majority of cases.Parallel distribution is enabled by default except for
CacheStream.iterator()andCacheStream.spliterator()- Specified by:
parallelDistributionin interfaceBaseCacheStream<Integer,IntStream>- Specified by:
parallelDistributionin interfaceIntCacheStream- Returns:
- a stream with parallel distribution enabled.
-
filterKeySegments
public IntCacheStream filterKeySegments(Set<Integer> segments)
Description copied from interface:IntCacheStreamFilters which entries are returned by what segment they are present in. This method can be substantially more efficient than using a regularCacheStream.filter(Predicate)method as this can control what nodes are asked for data and what entries are read from the underlying CacheStore if present.- Specified by:
filterKeySegmentsin interfaceBaseCacheStream<Integer,IntStream>- Specified by:
filterKeySegmentsin interfaceIntCacheStream- Parameters:
segments- The segments to use for this stream operation. Any segments not in this set will be ignored.- Returns:
- a stream with the segments filtered.
-
filterKeySegments
public IntCacheStream filterKeySegments(org.infinispan.commons.util.IntSet segments)
Description copied from interface:BaseCacheStreamFilters which entries are returned by what segment they are present in. This method can be substantially more efficient than using a regularCacheStream.filter(Predicate)method as this can control what nodes are asked for data and what entries are read from the underlying CacheStore if present.- Specified by:
filterKeySegmentsin interfaceBaseCacheStream<Integer,IntStream>- Parameters:
segments- The segments to use for this stream operation. Any segments not in this set will be ignored.- Returns:
- a stream with the segments filtered.
-
filterKeys
public IntCacheStream filterKeys(Set<?> keys)
Description copied from interface:IntCacheStreamFilters which entries are returned by only returning ones that map to the given key. This method will be faster than a regularCacheStream.filter(Predicate)if the filter is holding references to the same keys.- Specified by:
filterKeysin interfaceBaseCacheStream<Integer,IntStream>- Specified by:
filterKeysin interfaceIntCacheStream- Parameters:
keys- The keys that this stream will only operate on.- Returns:
- a stream with the keys filtered.
-
distributedBatchSize
public IntCacheStream distributedBatchSize(int batchSize)
Description copied from interface:IntCacheStreamControls how many keys are returned from a remote node when using a stream terminal operation with a distributed cache to back this stream. This value is ignored when terminal operators that don't track keys are used. Key tracking terminal operators areCacheStream.iterator(),CacheStream.spliterator(),CacheStream.forEach(Consumer). Please see those methods for additional information on how this value may affect them.This value may be used in the case of a a terminal operator that doesn't track keys if an intermediate operation is performed that requires bringing keys locally to do computations. Examples of such intermediate operations are
CacheStream.sorted(),CacheStream.sorted(Comparator),CacheStream.distinct(),CacheStream.limit(long),CacheStream.skip(long)This value is always ignored when this stream is backed by a cache that is not distributed as all values are already local.
- Specified by:
distributedBatchSizein interfaceBaseCacheStream<Integer,IntStream>- Specified by:
distributedBatchSizein interfaceIntCacheStream- Parameters:
batchSize- The size of each batch. This defaults to the state transfer chunk size.- Returns:
- a stream with the batch size updated
-
segmentCompletionListener
public IntCacheStream segmentCompletionListener(BaseCacheStream.SegmentCompletionListener listener)
Description copied from interface:IntCacheStreamAllows registration of a segment completion listener that is notified when a segment has completed processing. If the terminal operator has a short circuit this listener may never be called.This method is designed for the sole purpose of use with the
CacheStream.iterator()to allow for a user to track completion of segments as they are returned from the iterator. Behavior of other methods is not specified. Please seeCacheStream.iterator()for more information.Multiple listeners may be registered upon multiple invocations of this method. The ordering of notified listeners is not specified.
This is only used if this stream did not invoke
BaseCacheStream.disableRehashAware()and has no flat map based operations. If this is done no segments will be notified.- Specified by:
segmentCompletionListenerin interfaceBaseCacheStream<Integer,IntStream>- Specified by:
segmentCompletionListenerin interfaceIntCacheStream- Parameters:
listener- The listener that will be called back as segments are completed.- Returns:
- a stream with the listener registered.
-
disableRehashAware
public IntCacheStream disableRehashAware()
Description copied from interface:IntCacheStreamDisables tracking of rehash events that could occur to the underlying cache. If a rehash event occurs while a terminal operation is being performed it is possible for some values that are in the cache to not be found. Note that you will never have an entry duplicated when rehash awareness is disabled, only lost values.Most terminal operations will run faster with rehash awareness disabled even without a rehash occuring. However if a rehash occurs with this disabled be prepared to possibly receive only a subset of values.
- Specified by:
disableRehashAwarein interfaceBaseCacheStream<Integer,IntStream>- Specified by:
disableRehashAwarein interfaceIntCacheStream- Returns:
- a stream with rehash awareness disabled.
-
timeout
public IntCacheStream timeout(long timeout, TimeUnit unit)
Description copied from interface:IntCacheStreamSets a given time to wait for a remote operation to respond by. This timeout does nothing if the terminal operation does not go remote.If a timeout does occur then a
TimeoutExceptionis thrown from the terminal operation invoking thread or on the next call to theIteratororSpliterator.Note that if a rehash occurs this timeout value is reset for the subsequent retry if rehash aware is enabled.
- Specified by:
timeoutin interfaceBaseCacheStream<Integer,IntStream>- Specified by:
timeoutin interfaceIntCacheStream- Parameters:
timeout- the maximum time to waitunit- the time unit of the timeout argument- Returns:
- a stream with the timeout set
-
cacheStream
protected <R> DistributedCacheStream<Original,R> cacheStream()
-
doubleCacheStream
protected DistributedDoubleCacheStream<Original> doubleCacheStream()
-
longCacheStream
protected DistributedLongCacheStream<Original> longCacheStream()
-
-