io.smallrye.faulttolerance.internal.RequestScopeActivator Maven / Gradle / Ivy
package io.smallrye.faulttolerance.internal;
import static io.smallrye.faulttolerance.internal.InternalLogger.LOG;
import jakarta.enterprise.context.control.RequestContextController;
import io.smallrye.faulttolerance.core.FaultToleranceStrategy;
import io.smallrye.faulttolerance.core.InvocationContext;
public class RequestScopeActivator implements FaultToleranceStrategy {
private final FaultToleranceStrategy delegate;
private final RequestContextController requestContextController;
public RequestScopeActivator(FaultToleranceStrategy delegate, RequestContextController requestContextController) {
this.delegate = delegate;
this.requestContextController = requestContextController;
}
@Override
public V apply(InvocationContext ctx) throws Exception {
// for CompletionStage, the requestContextController.activate/deactivate pair here
// is the minimum to pass TCK; for anything serious, Context Propagation is required
LOG.trace("RequestScopeActivator started");
try {
requestContextController.activate();
return delegate.apply(ctx);
} finally {
requestContextController.deactivate();
LOG.trace("RequestScopeActivator finished");
}
}
}