org.opensearch.migrations.replay.util.TextTrackedFuture Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of trafficReplayer Show documentation
Show all versions of trafficReplayer Show documentation
Everything opensearch migrations
package org.opensearch.migrations.replay.util;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
import java.util.stream.Stream;
import lombok.NonNull;
public class TextTrackedFuture extends TrackedFuture {
public TextTrackedFuture(String diagnosticLabel) {
this(new CompletableFuture<>(), () -> diagnosticLabel);
}
public TextTrackedFuture(Supplier diagnosticSupplier) {
this(new CompletableFuture<>(), diagnosticSupplier);
}
public TextTrackedFuture(@NonNull CompletableFuture future, Supplier diagnosticSupplier) {
super(future, diagnosticSupplier);
}
public TextTrackedFuture(@NonNull CompletableFuture future, String diagnosticLabel) {
super(future, () -> diagnosticLabel);
}
public static TextTrackedFuture failedFuture(Throwable e, Supplier diagnosticSupplier) {
return new TextTrackedFuture<>(CompletableFuture.failedFuture(e), diagnosticSupplier);
}
public static TextTrackedFuture completedFuture(U v, Supplier diagnosticSupplier) {
return new TextTrackedFuture<>(CompletableFuture.completedFuture(v), diagnosticSupplier);
}
public static TextTrackedFuture allOf(
TrackedFuture[] allRemainingWorkArray,
Supplier diagnosticSupplier
) {
return allOf(Arrays.stream(allRemainingWorkArray), diagnosticSupplier);
}
public static TextTrackedFuture allOf(
Stream> allRemainingWorkStream,
Supplier diagnosticSupplier
) {
return new TextTrackedFuture<>(
CompletableFuture.allOf(allRemainingWorkStream.map(tcf -> tcf.future).toArray(CompletableFuture[]::new)),
diagnosticSupplier
);
}
}