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

io.quarkus.smallrye.faulttolerance.runtime.SmallRyeFaultToleranceRecorder Maven / Gradle / Ivy

There is a newer version: 3.17.0.CR1
Show newest version
package io.quarkus.smallrye.faulttolerance.runtime;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import jakarta.enterprise.inject.spi.DeploymentException;

import org.eclipse.microprofile.faulttolerance.exceptions.FaultToleranceDefinitionException;

import io.quarkus.arc.Arc;
import io.quarkus.runtime.annotations.Recorder;
import io.smallrye.faulttolerance.autoconfig.FaultToleranceMethod;
import io.smallrye.faulttolerance.config.FaultToleranceOperation;

@Recorder
public class SmallRyeFaultToleranceRecorder {

    public void createFaultToleranceOperation(List ftMethods) {
        List allExceptions = new ArrayList<>();
        Map operationCache = new HashMap<>(
                ftMethods.size());
        for (FaultToleranceMethod ftMethod : ftMethods) {
            FaultToleranceOperation operation = FaultToleranceOperation.create(ftMethod);
            try {
                operation.validate();

                QuarkusFaultToleranceOperationProvider.CacheKey cacheKey = new QuarkusFaultToleranceOperationProvider.CacheKey(
                        ftMethod.beanClass, ftMethod.method.reflect());
                operationCache.put(cacheKey, operation);
            } catch (FaultToleranceDefinitionException | NoSuchMethodException e) {
                allExceptions.add(e);
            }
        }

        if (!allExceptions.isEmpty()) {
            if (allExceptions.size() == 1) {
                Throwable error = allExceptions.get(0);
                if (error instanceof DeploymentException) {
                    throw (DeploymentException) error;
                } else {
                    throw new DeploymentException(error);
                }
            } else {
                StringBuilder message = new StringBuilder("Found " + allExceptions.size() + " deployment problems: ");
                int idx = 1;
                for (Throwable error : allExceptions) {
                    message.append("\n").append("[").append(idx++).append("] ").append(error.getMessage());
                }
                DeploymentException deploymentException = new DeploymentException(message.toString());
                for (Throwable error : allExceptions) {
                    deploymentException.addSuppressed(error);
                }
                throw deploymentException;
            }
        }

        Arc.container().instance(QuarkusFaultToleranceOperationProvider.class).get().init(operationCache);
    }

    public void initExistingCircuitBreakerNames(Set names) {
        Arc.container().instance(QuarkusExistingCircuitBreakerNames.class).get().init(names);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy