io.vrap.rmf.base.client.http.PolicyMiddlewareImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rmf-java-base Show documentation
Show all versions of rmf-java-base Show documentation
The e-commerce SDK from commercetools Composable Commerce for Java
package io.vrap.rmf.base.client.http;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import io.vrap.rmf.base.client.*;
import dev.failsafe.Failsafe;
import dev.failsafe.FailsafeExecutor;
import dev.failsafe.Policy;
import dev.failsafe.spi.Scheduler;
/**
* Implementation for a failsafe requests handling
*/
public class PolicyMiddlewareImpl implements AutoCloseable, PolicyMiddleware {
private final FailsafeExecutor> failsafeExecutor;
PolicyMiddlewareImpl(final Scheduler scheduler, final List>> policies) {
this.failsafeExecutor = Failsafe.with(policies).with(scheduler);
}
@Override
public CompletableFuture> invoke(final ApiHttpRequest request,
final Function>> next) {
return failsafeExecutor.getStageAsync(() -> next.apply(request));
}
@Override
public void close() {
}
}