Skip to content

Commit

Permalink
Make a custom ContextManagerProvider with a single manager
Browse files Browse the repository at this point in the history
Because Quarkus doesn't care about one-per CL and Franz said this is a
bottleneck for some reason
  • Loading branch information
FroMage committed Apr 8, 2024
1 parent 9fc4e97 commit ba4b973
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.quarkus.smallrye.context.runtime;

import org.eclipse.microprofile.context.spi.ContextManager;

import io.smallrye.context.SmallRyeContextManager;
import io.smallrye.context.SmallRyeContextManagerProvider;

/**
* Quarkus doesn't need one manager per CL, we only have the one
*/
public class QuarkusContextManagerProvider extends SmallRyeContextManagerProvider {

private SmallRyeContextManager contextManager;

@Override
public SmallRyeContextManager getContextManager(ClassLoader classLoader) {
return contextManager;
}

@Override
public SmallRyeContextManager getContextManager() {
return contextManager;
}

@Override
public ContextManager findContextManager(ClassLoader classLoader) {
return contextManager;
}

@Override
public void registerContextManager(ContextManager manager, ClassLoader classLoader) {
if (manager instanceof SmallRyeContextManager == false) {
throw new IllegalArgumentException("Only instances of SmallRyeContextManager are supported: " + manager);
}
contextManager = (SmallRyeContextManager) manager;
}

@Override
public void releaseContextManager(ContextManager manager) {
contextManager = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void configureStaticInit(List<ThreadContextProvider> discoveredProviders,
// build the manager at static init time
// in the live-reload mode, the provider instance may be already set in the previous start
if (ContextManagerProvider.INSTANCE.get() == null) {
ContextManagerProvider contextManagerProvider = new SmallRyeContextManagerProvider();
ContextManagerProvider contextManagerProvider = new QuarkusContextManagerProvider();
ContextManagerProvider.register(contextManagerProvider);
}

Expand Down

0 comments on commit ba4b973

Please sign in to comment.