
org.zalando.riptide.failsafe.CompositeDelayFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of riptide-failsafe Show documentation
Show all versions of riptide-failsafe Show documentation
Client side response routing
The newest version!
package org.zalando.riptide.failsafe;
import dev.failsafe.ExecutionContext;
import dev.failsafe.function.ContextualSupplier;
import lombok.AllArgsConstructor;
import org.apiguardian.api.API;
import java.time.Duration;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import static org.apiguardian.api.API.Status.EXPERIMENTAL;
@API(status = EXPERIMENTAL)
@AllArgsConstructor
public final class CompositeDelayFunction implements ContextualSupplier {
private final Collection> functions;
@Override
public Duration get(final ExecutionContext context) throws Throwable {
return functions.stream()
.map(function -> {
try {
return function.get(context);
} catch (Throwable e) {
throw new RuntimeException(e);
}
})
.filter(Objects::nonNull)
.filter(delay -> !Duration.ofMinutes(-1).equals(delay))
.findFirst()
.orElse(Duration.ofMinutes(-1));
}
@SafeVarargs
public static ContextualSupplier composite(
final ContextualSupplier... functions) {
return new CompositeDelayFunction<>(Arrays.asList(functions));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy