package io.quarkus.smallrye.context.runtime;

import java.util.concurrent.ExecutorService;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Singleton;

import org.eclipse.microprofile.context.ManagedExecutor;
import org.eclipse.microprofile.context.ThreadContext;

import io.smallrye.context.impl.ManagedExecutorImpl;
import io.smallrye.context.impl.ThreadContextImpl;

@ApplicationScoped
public class SmallRyeContextPropagationProvider {

    private volatile ManagedExecutorImpl managedExecutor;

    void initialize(ExecutorService executorService) {
        managedExecutor = new ManagedExecutorImpl(-1, -1, (ThreadContextImpl) getAllThreadContext(), executorService, "no-ip");
    }

    @Produces
    @Singleton
    public ThreadContext getAllThreadContext() {
        return ThreadContext.builder().propagated(ThreadContext.ALL_REMAINING).cleared().unchanged().build();
    }

    @Produces
    @Singleton
    public ManagedExecutor getAllManagedExecutor() {
        return managedExecutor;
    }

}

@@ -35,24 +35,47 @@
 t.runtime;%0A%0A
+import java.util.List;%0A
 import java.
@@ -760,16 +760,426 @@
 %22no-ip%22)
+ %7B%0A            @Override%0A            public void shutdown() %7B%0A                throw new IllegalStateException(%22This executor is managed by the container and cannot be shut down.%22);%0A            %7D%0A%0A            @Override%0A            public List%3CRunnable%3E shutdownNow() %7B%0A                throw new IllegalStateException(%22This executor is managed by the container and cannot be shut down.%22);%0A            %7D%0A        %7D
 ;%0A    %7D%0A

Make sure we follow the MP-CP spec and disallow our container-managed executor to be shut down