io.smallrye.faulttolerance.internal.StrategyCache Maven / Gradle / Ivy
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());
}
}