private ContextControl getContextControl() { CdiContainer container = CdiContainerLoader.getCdiContainer(); return container.getContextControl(); } }
private boolean isCdiContainerBooted(final CdiContainer cdiContainer) { // For the time being, this simple check will reliably detect, if the container is up and running. return cdiContainer.getBeanManager() != null; }
public void stopContexts() { contextControl.stopContexts(); }
public static void main(String[] args) { CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer(); cdiContainer.boot(); ContextControl contextControl = cdiContainer.getContextControl(); contextControl.startContext(ApplicationScoped.class); ServiceLoader<Showcase> showcaseLoader = ServiceLoader.load(Showcase.class); Iterator<Showcase> showcaseIterator = showcaseLoader.iterator(); if (!showcaseIterator.hasNext()) { throw new RuntimeException("No showcases found"); } while (showcaseIterator.hasNext()) { BeanProvider.injectFields(showcaseIterator.next()).run(); } cdiContainer.shutdown(); }
@Test public void testContainerBoot() { CdiContainer cc = CdiContainerLoader.getCdiContainer(); Assert.assertNotNull(cc); cc.boot(); cc.getContextControl().startContexts(); BeanManager bm = cc.getBeanManager(); Assert.assertNotNull(bm); Set<Bean<?>> beans = bm.getBeans(CarRepair.class); Bean<?> bean = bm.resolve(beans); CarRepair carRepair = (CarRepair) bm.getReference(bean, CarRepair.class, bm.createCreationalContext(bean)); Assert.assertNotNull(carRepair); Assert.assertNotNull(carRepair.getCar()); Assert.assertNotNull(carRepair.getCar().getUser()); cc.shutdown(); }
@Override public void start() { validateConfiguration(); setProbeClassLoader(); LOG.debug("starting OpenWebBeans container"); container = CdiContainerLoader.getCdiContainer(); container.boot(); container.getContextControl().startContexts(); isValid = true; }
private ContextControlWrapper() { final CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer(); if (!isCdiContainerBooted(cdiContainer)) { LOG.info("booting cdi container"); long start = System.currentTimeMillis(); cdiContainer.boot(); long end = System.currentTimeMillis(); LOG.log(INFO, "booting cdi container finished in {0} ms", end - start); } contextControl = cdiContainer.getContextControl(); }
@Override public void stop() { if (container != null && isValid) { LOG.debug("stopping OpenWebBeans container"); container.getContextControl().stopContexts(); container.shutdown(); unsetProbeClassLoader(); } }
void applyAfterFeatureConfig() { ProjectStageProducer.setProjectStage(previousProjectStage); previousProjectStage = null; CdiContainer container = CdiContainerLoader.getCdiContainer(); stopStartedScopes(container); if (this.containerStarted) { if (isStopContainerAllowed()) { shutdownExternalContainers(); container.shutdown(); //stop the container on the same level which started it containerStarted = false; } } }
@Override public void run(RunNotifier runNotifier) { CdiContainer container = CdiContainerLoader.getCdiContainer(); if (!containerStarted) { container.boot(CdiTestSuiteRunner.getTestContainerConfig()); containerStarted = true; } super.run(runNotifier); }
private void stopStartedScopes(CdiContainer container) { while (!this.startedScopes.empty()) { Class<? extends Annotation> scopeAnnotation = this.startedScopes.pop(); //TODO check if context was started by parent try { container.getContextControl().stopContext(scopeAnnotation); onScopeStopped(scopeAnnotation); } catch (RuntimeException e) { Logger logger = Logger.getLogger(CdiCucumberTestRunner.class.getName()); logger.setLevel(Level.SEVERE); logger.log(Level.SEVERE, "failed to stop scope @" + scopeAnnotation.getName(), e); } } }
@Override public void requestDestroyed(ServletRequestEvent servletRequestEvent) { LOG.log(Level.FINER,"Request done."); ContextControl contextControl = (ContextControl)servletRequestEvent.getServletRequest() .getAttribute(CDI_REQ_CONTEXT); contextControl.stopContext(RequestScoped.class); }
@Override protected void doStop() throws Exception { super.doStop(); if (cdiContainer != null) { cdiContainer.shutdown(); } } }
public void startContexts() { contextControl.startContexts(); }
@Override protected void doStart() throws Exception { // TODO: Use standard CDI Java SE support when CDI 2.0 becomes a prerequisite CdiContainer container = getCdiContainer(); container.boot(); container.getContextControl().startContexts(); cdiContainer = container; super.doStart(); postProcessContext(); warnIfNoCamelFound(); }
private void checkActiveContextControlImplementation() { if (customContextControlDetected != null) { return; } customContextControlDetected = !CdiContainerLoader.getCdiContainer().getContextControl() .getClass().getName().startsWith("org.apache.deltaspike."); }
void applyAfterClassConfig() { CdiContainer container = CdiContainerLoader.getCdiContainer(); stopStartedScopes(container); if (this.containerStarted) { if (CdiTestSuiteRunner.isStopContainerAllowed()) { shutdownExternalContainers(); container.shutdown(); //stop the container on the same level which started it CdiTestSuiteRunner.setContainerStarted(false); } } }
private void stopStartedScopes() { if (this.contextControl == null) { return; } while (!this.scopes.empty()) { this.contextControl.get().stopContext(this.scopes.pop()); } this.contextControl.destroy(); } }
@Override public BeanManager getBeanManager() { return OpenWebBeansTestContainer.getCdiContainer().getBeanManager(); } }
private void warnIfNoCamelFound() { BeanManager manager = cdiContainer.getBeanManager(); Set<Bean<?>> contexts = manager.getBeans(CamelContext.class, ANY); // Warn if there is no CDI Camel contexts if (contexts.isEmpty()) { LOG.warn("Camel CDI main has started with no Camel context!"); } }