
org.opensearch.migrations.replay.util.TrackedFutureStringFormatter Maven / Gradle / Ivy
package org.opensearch.migrations.replay.util;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import lombok.NonNull;
import lombok.SneakyThrows;
public class TrackedFutureStringFormatter {
private TrackedFutureStringFormatter() {}
public static String format(TrackedFuture f) {
return format(f, x -> null);
}
public static String format(
TrackedFuture f,
@NonNull Function, String> resultFormatter
) {
return f.walkParentsAsStream()
.map(kvp -> stringFormatFutureWithDiagnostics(f, kvp, resultFormatter))
.collect(Collectors.joining("<-"));
}
@SneakyThrows
protected static String stringFormatFutureWithDiagnostics(
TrackedFuture f,
@NonNull TrackedFuture tf,
@NonNull Function, String> resultFormatter
) {
var diagnosticInfo = tf.diagnosticSupplier.get();
var isDone = tf.isDone();
return "["
+ System.identityHashCode(tf)
+ "] "
+ diagnosticInfo
+ (isDone
? "[" + Optional.ofNullable(resultFormatter.apply(tf)).orElse("^") + "]"
: Optional.ofNullable(tf.innerComposedPendingCompletableFutureReference)
.map(r -> (TrackedFuture) r.get())
.map(df -> " --[[" + format(df, resultFormatter) + " ]] ")
.orElse("[…]"));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy