All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vrap.rmf.base.client.http.PolicyMiddlewareImpl Maven / Gradle / Ivy

There is a newer version: 17.17.0
Show newest version

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() {
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy