Class MultipleFuturesAvailabilityHelper
- java.lang.Object
-
- org.apache.flink.streaming.runtime.io.MultipleFuturesAvailabilityHelper
-
@Internal public class MultipleFuturesAvailabilityHelper extends Object
This class is semi-thread safe. Only methodnotifyCompletion()
is allowed to be executed from an outside of the task thread.It solves a problem of a potential memory leak as described in FLINK-25728. In short we have to ensure, that if there is one input (future) that rarely (or never) completes, that such future would not prevent previously returned combined futures (like
CompletableFuture.anyOf(CompletableFuture[])
from being garbage collected. Additionally, we don't want to accumulate more and more completion stages on such rarely completed future, so we are registeringCompletableFuture.thenRun(Runnable)
only if it has not already been done.Note
resetToUnAvailable()
doesn't de register previously registered futures. If future was registered in the past, but for whatever reason now it is not, such future can still complete the newly created future.It might be no longer needed after upgrading to JDK9 (https://bugs.openjdk.java.net/browse/JDK-8160402).
-
-
Constructor Summary
Constructors Constructor Description MultipleFuturesAvailabilityHelper(int size)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
anyOf(int idx, CompletableFuture<?> availabilityFuture)
CombineavailabilityFuture
using anyOf logic with other previously registered futures.CompletableFuture<?>
getAvailableFuture()
void
resetToUnAvailable()
-
-
-
Method Detail
-
getAvailableFuture
public CompletableFuture<?> getAvailableFuture()
- Returns:
- combined future using anyOf logic
-
resetToUnAvailable
public void resetToUnAvailable()
-
anyOf
public void anyOf(int idx, CompletableFuture<?> availabilityFuture)
CombineavailabilityFuture
using anyOf logic with other previously registered futures.
-
-