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

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

There is a newer version: 6.6.2
Show newest version
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");
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy