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

io.smallrye.faulttolerance.internal.StrategyCache Maven / Gradle / Ivy

There is a newer version: 6.6.2
Show newest version
package io.smallrye.faulttolerance.internal;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

import jakarta.inject.Singleton;

import io.smallrye.faulttolerance.core.FaultToleranceStrategy;
import io.smallrye.faulttolerance.core.metrics.MetricsRecorder;

@Singleton
public class StrategyCache {
    private final Map> strategies = new ConcurrentHashMap<>();
    private final Map metricsRecorders = new ConcurrentHashMap<>();

    @SuppressWarnings("unchecked")
    public  FaultToleranceStrategy getStrategy(InterceptionPoint point,
            Supplier> producer) {
        return (FaultToleranceStrategy) strategies.computeIfAbsent(point, ignored -> producer.get());
    }

    public MetricsRecorder getMetrics(InterceptionPoint point, Supplier producer) {
        return metricsRecorders.computeIfAbsent(point, ignored -> producer.get());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy