org.eclipse.microprofile.context.spi.ContextManagerProvider Java Examples
The following examples show how to use
org.eclipse.microprofile.context.spi.ContextManagerProvider.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SmallRyeContextPropagationRecorder.java From quarkus with Apache License 2.0 | 5 votes |
public void configureStaticInit(List<ThreadContextProvider> discoveredProviders, List<ContextManagerExtension> discoveredExtensions) { // 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.register(contextManagerProvider); } // do what config we can here, but we need the runtime executor service to finish builder = (SmallRyeContextManager.Builder) ContextManagerProvider.instance() .getContextManagerBuilder(); builder.withThreadContextProviders(discoveredProviders.toArray(new ThreadContextProvider[0])); builder.withContextManagerExtensions(discoveredExtensions.toArray(new ContextManagerExtension[0])); }
Example #2
Source File: SmallRyeContextPropagationRecorder.java From quarkus with Apache License 2.0 | 5 votes |
public void configureRuntime(BeanContainer container, ExecutorService executorService) { // associate the static init manager to the runtime CL ContextManagerProvider contextManagerProvider = ContextManagerProvider.instance(); // finish building our manager builder.withDefaultExecutorService(executorService); SmallRyeContextManager contextManager = builder.build(); contextManagerProvider.registerContextManager(contextManager, Thread.currentThread().getContextClassLoader()); // initialise injection SmallRyeContextPropagationProvider cpProvider = container.instance(SmallRyeContextPropagationProvider.class); cpProvider.initialize(executorService); }
Example #3
Source File: ContextManagerTest.java From microprofile-context-propagation with Apache License 2.0 | 4 votes |
/** * Verify obtaining a ContextManager builder from the ContextManagerProvider. Then validate building, * registering, and releasing a custom ContextManager. If a ContextManager builder is not supported * then this test will no-op. */ @Test public void builderForContextManagerIsProvided() { ContextManagerProvider provider = ContextManagerProvider.instance(); ClassLoader classLoader = ContextManagerTest.class.getClassLoader(); Builder contextManagerBuilder = null; try { //obtain the ContextManagerBuilder contextManagerBuilder = provider.getContextManagerBuilder(); Assert.assertNotNull(contextManagerBuilder, "MicroProfile Context Propagation implementation does not provide a ContextManager builder."); } catch (UnsupportedOperationException ex1) { //ContextManagerProvider.getContextManagerBuilder() support is optional. System.out.println("ContextManagerProvider.getContextManagerBuilder is not supported."); //Verify ContextManagerProvider.registerContextManager() is also unsupported. try { provider.registerContextManager(provider.getContextManager(), classLoader); Assert.fail("ContextManagerProvider.registerContextManager should not be supported, " + "if ContextManagerProvider.getContextManagerBuilder is not supported."); } catch (UnsupportedOperationException ex2) { System.out.println("ContextManagerProvider.registerContextManager is not supported."); } //Verify ContextManagerProvider.releaseContextManager() is also unsupported. try { provider.releaseContextManager(provider.getContextManager()); Assert.fail("ContextManagerProvider.releaseContextManager should not be supported, " + "if ContextManagerProvider.getContextManagerBuilder is not supported."); } catch (UnsupportedOperationException ex3) { System.out.println("ContextManagerProvider.releaseContextManager is not supported."); } //Unsupported path of test has passed. return; } //build and register a ContextManager ContextManager builtManager = contextManagerBuilder.build(); provider.registerContextManager(builtManager, classLoader); ContextManager registeredManager = provider.getContextManager(classLoader); Assert.assertEquals(builtManager, registeredManager, "ContextManagerProvider.getContextManager(classLoader) did not return the same manager that was registered."); //release the ContextManager provider.releaseContextManager(registeredManager); Assert.assertNotEquals(builtManager, provider.getContextManager(classLoader), "ContextManager was not released from the ContextManagerProvider."); }
Example #4
Source File: TckTest.java From microprofile-context-propagation with Apache License 2.0 | 4 votes |
@Test public void providerSet() { ContextManagerProvider provider = ContextManagerProvider.instance(); Assert.assertNotNull(provider, "ContextManagerProvider is not set"); }
Example #5
Source File: ManagedExecutor.java From microprofile-context-propagation with Apache License 2.0 | 2 votes |
/** * Creates a new {@link Builder} instance. * * @return a new {@link Builder} instance. */ public static Builder builder() { return ContextManagerProvider.instance().getContextManager().newManagedExecutorBuilder(); }
Example #6
Source File: ThreadContext.java From microprofile-context-propagation with Apache License 2.0 | 2 votes |
/** * Creates a new {@link Builder} instance. * * @return a new {@link Builder} instance. */ public static Builder builder() { return ContextManagerProvider.instance().getContextManager().newThreadContextBuilder(); }