diff --git a/core/src/main/java/org/infinispan/CacheStream.java b/core/src/main/java/org/infinispan/CacheStream.java
index 6454358d85cb..29c9a1ed837f 100644
--- a/core/src/main/java/org/infinispan/CacheStream.java
+++ b/core/src/main/java/org/infinispan/CacheStream.java
@@ -217,6 +217,27 @@ interface SegmentCompletionListener {
*/
void forEach(SerializableConsumer super R> action);
+ /**
+ * Same as {@link CacheStream#forEach(Consumer)} except that it takes a {@link BiConsumer} that provides access
+ * to the underlying {@link Cache} that is backing this stream.
+ *
+ * Note that the CacheAware interface is not supported for injection using this method as the cache
+ * is provided in the consumer directly.
+ * @param action consumer to be ran for each element in the stream
+ * @param key type of the cache
+ * @param value type of the cache
+ */
+ void forEach(BiConsumer, ? super R> action);
+
+ /**
+ * Same as {@link CacheStream#forEach(BiConsumer)} except that the BiConsumer must also implement
+ * Serializable
+ * @param action consumer to be ran for each element in the stream
+ * @param key type of the cache
+ * @param value type of the cache
+ */
+ void forEach(SerializableBiConsumer, ? super R> action);
+
/**
* {@inheritDoc}
*
Usage of this operator requires closing this stream after you are done with the iterator. The preferred
diff --git a/core/src/main/java/org/infinispan/DoubleCacheStream.java b/core/src/main/java/org/infinispan/DoubleCacheStream.java
index 6de3bf444954..0cba19b562a4 100644
--- a/core/src/main/java/org/infinispan/DoubleCacheStream.java
+++ b/core/src/main/java/org/infinispan/DoubleCacheStream.java
@@ -1,5 +1,6 @@
package org.infinispan;
+import org.infinispan.util.function.SerializableBiConsumer;
import org.infinispan.util.function.SerializableDoubleBinaryOperator;
import org.infinispan.util.function.SerializableDoubleConsumer;
import org.infinispan.util.function.SerializableDoubleFunction;
@@ -8,7 +9,6 @@
import org.infinispan.util.function.SerializableDoubleToLongFunction;
import org.infinispan.util.function.SerializableDoubleUnaryOperator;
import org.infinispan.util.function.SerializableObjDoubleConsumer;
-import org.infinispan.util.function.SerializableBiConsumer;
import org.infinispan.util.function.SerializableSupplier;
import java.util.OptionalDouble;
@@ -198,6 +198,27 @@ public interface DoubleCacheStream extends DoubleStream {
*/
void forEach(SerializableDoubleConsumer action);
+ /**
+ * Same as {@link DoubleCacheStream#forEach(DoubleConsumer)} except that it takes an {@link ObjDoubleConsumer} that
+ * provides access to the underlying {@link Cache} that is backing this stream.
+ *
+ * Note that the CacheAware interface is not supported for injection using this method as the cache
+ * is provided in the consumer directly.
+ * @param action consumer to be ran for each element in the stream
+ * @param key type of the cache
+ * @param value type of the cache
+ */
+ void forEach(ObjDoubleConsumer> action);
+
+ /**
+ * Same as {@link DoubleCacheStream#forEach(ObjDoubleConsumer)} except that the BiConsumer must also implement
+ * Serializable
+ * @param action consumer to be ran for each element in the stream
+ * @param key type of the cache
+ * @param value type of the cache
+ */
+ void forEach(SerializableObjDoubleConsumer> action);
+
/**
* Same as {@link DoubleCacheStream#reduce(double, DoubleBinaryOperator)} except that the DoubleBinaryOperator must
* also implement Serializable
diff --git a/core/src/main/java/org/infinispan/IntCacheStream.java b/core/src/main/java/org/infinispan/IntCacheStream.java
index 5965149c05e7..9d57b7cf6632 100644
--- a/core/src/main/java/org/infinispan/IntCacheStream.java
+++ b/core/src/main/java/org/infinispan/IntCacheStream.java
@@ -198,6 +198,27 @@ public interface IntCacheStream extends IntStream {
*/
void forEach(SerializableIntConsumer action);
+ /**
+ * Same as {@link IntCacheStream#forEach(IntConsumer)} except that it takes an {@link ObjIntConsumer} that
+ * provides access to the underlying {@link Cache} that is backing this stream.
+ *
+ * Note that the CacheAware interface is not supported for injection using this method as the cache
+ * is provided in the consumer directly.
+ * @param action consumer to be ran for each element in the stream
+ * @param key type of the cache
+ * @param value type of the cache
+ */
+ void forEach(ObjIntConsumer> action);
+
+ /**
+ * Same as {@link IntCacheStream#forEach(ObjIntConsumer)} except that the BiConsumer must also implement
+ * Serializable
+ * @param action consumer to be ran for each element in the stream
+ * @param key type of the cache
+ * @param value type of the cache
+ */
+ void forEach(SerializableObjIntConsumer> action);
+
/**
* Same as {@link IntCacheStream#reduce(int, IntBinaryOperator)} except that the IntBinaryOperator
* must also implement Serializable
diff --git a/core/src/main/java/org/infinispan/LongCacheStream.java b/core/src/main/java/org/infinispan/LongCacheStream.java
index 70847ff197e9..a0975fa53566 100644
--- a/core/src/main/java/org/infinispan/LongCacheStream.java
+++ b/core/src/main/java/org/infinispan/LongCacheStream.java
@@ -206,6 +206,27 @@ public interface LongCacheStream extends LongStream {
*/
void forEach(SerializableLongConsumer action);
+ /**
+ * Same as {@link LongCacheStream#forEach(LongConsumer)} except that it takes an {@link ObjLongConsumer} that
+ * provides access to the underlying {@link Cache} that is backing this stream.
+ *
+ * Note that the CacheAware interface is not supported for injection using this method as the cache
+ * is provided in the consumer directly.
+ * @param action consumer to be ran for each element in the stream
+ * @param key type of the cache
+ * @param value type of the cache
+ */
+ void forEach(ObjLongConsumer> action);
+
+ /**
+ * Same as {@link LongCacheStream#forEach(ObjLongConsumer)} except that the BiConsumer must also implement
+ * Serializable
+ * @param action consumer to be ran for each element in the stream
+ * @param key type of the cache
+ * @param value type of the cache
+ */
+ void forEach(SerializableObjLongConsumer> action);
+
/**
* Same as {@link LongCacheStream#reduce(long, LongBinaryOperator)} except that the LongBinaryOperator must
* also implement Serializable.
diff --git a/core/src/main/java/org/infinispan/stream/impl/AbstractCacheStream.java b/core/src/main/java/org/infinispan/stream/impl/AbstractCacheStream.java
index 0b9064b55230..e1f2e4013695 100644
--- a/core/src/main/java/org/infinispan/stream/impl/AbstractCacheStream.java
+++ b/core/src/main/java/org/infinispan/stream/impl/AbstractCacheStream.java
@@ -43,9 +43,8 @@
* primitive types.
* @param The type returned by the stream
* @param The stream interface
- * @param The consumer for this stream
*/
-public abstract class AbstractCacheStream, S2 extends S, T_CONS> implements BaseStream {
+public abstract class AbstractCacheStream, S2 extends S> implements BaseStream {
protected final Log log = LogFactory.getLog(getClass());
protected final Queue intermediateOperations;
@@ -100,7 +99,7 @@ protected AbstractCacheStream(Address localAddress, boolean parallel, Distributi
intermediateOperations = new ArrayDeque<>();
}
- protected AbstractCacheStream(AbstractCacheStream other) {
+ protected AbstractCacheStream(AbstractCacheStream other) {
this.intermediateOperations = other.intermediateOperations;
this.localIntermediateOperations = other.localIntermediateOperations;
this.localAddress = other.localAddress;
@@ -234,12 +233,12 @@ public void close() {
}
}
- R performOperation(Function function, boolean retryOnRehash, BinaryOperator accumulator,
+ R performOperation(Function super S2, ? extends R> function, boolean retryOnRehash, BinaryOperator accumulator,
Predicate super R> earlyTerminatePredicate) {
return performOperation(function, retryOnRehash, accumulator, earlyTerminatePredicate, true);
}
- R performOperation(Function function, boolean retryOnRehash, BinaryOperator accumulator,
+ R performOperation(Function super S2, ? extends R> function, boolean retryOnRehash, BinaryOperator accumulator,
Predicate super R> earlyTerminatePredicate, boolean ignoreSorting) {
// These operations are not affected by sorting, only by distinct
if (intermediateType.shouldUseIntermediate(!ignoreSorting && sorted, distinct)) {
@@ -254,7 +253,7 @@ R performOperation(Function function, boolean retryOnRehash,
}
}
- R performOperation(Function function, ResultsAccumulator remoteResults,
+ R performOperation(Function super S2, ? extends R> function, ResultsAccumulator remoteResults,
Predicate super R> earlyTerminatePredicate) {
ConsistentHash ch = dm.getConsistentHash();
TerminalOperation op = new SingleRunOperation<>(intermediateOperations,
@@ -283,7 +282,7 @@ R performOperation(Function function, ResultsAccumulator
}
}
- R performOperationRehashAware(Function function, boolean retryOnRehash,
+ R performOperationRehashAware(Function super S2, ? extends R> function, boolean retryOnRehash,
ResultsAccumulator remoteResults, Predicate super R> earlyTerminatePredicate) {
Set segmentsToProcess = segmentsToFilter;
TerminalOperation op;
@@ -353,10 +352,8 @@ R performOperationRehashAware(Function function, boolean ret
return remoteResults.currentValue;
}
- abstract KeyTrackingTerminalOperation