@Override public void requestInitialized(ServletRequestEvent servletRequestEvent) { LOG.log(Level.FINER,"Incoming request."); ContextControl contextControl = getContextControl(); servletRequestEvent.getServletRequest().setAttribute(CDI_REQ_CONTEXT, contextControl); contextControl.startContext(RequestScoped.class); }
@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); }
public void stopContexts() { contextControl.stopContexts(); }
@Override public void run() { try { contextControl.startContext(SessionScoped.class); contextControl.startContext(RequestScoped.class); 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); for (int i = 0; i < 100000; i++) { // we need the threads doing something ;) Assert.assertNotNull(carRepair.getCar()); Assert.assertNotNull(carRepair.getCar().getUser()); Assert.assertNull(carRepair.getCar().getUser().getName()); } contextControl.stopContext(RequestScoped.class); contextControl.stopContext(SessionScoped.class); } catch (Throwable e) { log.log(Level.SEVERE, "An exception happened on a new worker thread", e); numErrors.incrementAndGet(); } } };
cdiContainer.getContextControl().startContexts(); Assert.assertFalse(TestUser.isPreDestroyCalled()); cdiContainer.getContextControl().stopContexts();
public void startContexts() { contextControl.startContexts(); }
contextControl.stopContext(scopeAnnotation); contextControl.startContext(scopeAnnotation); this.startedScopes.add(scopeAnnotation);
cdiContainer.getContextControl().startContexts(); Assert.assertFalse(TestUser.isPreDestroyCalled()); cdiContainer.getContextControl().stopContexts(); cdiContainer.getContextControl().startContexts();
@Override public void start() { validateConfiguration(); setProbeClassLoader(); LOG.debug("starting OpenWebBeans container"); container = CdiContainerLoader.getCdiContainer(); container.boot(); container.getContextControl().startContexts(); isValid = true; }
contextControl.stopContext(scopeAnnotation); contextControl.startContext(scopeAnnotation); this.startedScopes.add(scopeAnnotation);
ctxCtrl.stopContext(ConversationScoped.class); ctxCtrl.stopContext(RequestScoped.class); ctxCtrl.stopContext(SessionScoped.class); ctxCtrlBean.destroy(ctxCtrl, ctxCtrlCreationalContext);
public void startContexts(Scheduled scheduled) { Collections.addAll(this.scopes, scheduled.startScopes()); if (!this.scopes.isEmpty()) { this.contextControl = BeanProvider.getDependent(ContextControl.class); for (Class<? extends Annotation> scopeAnnotation : this.scopes) { contextControl.get().startContext(scopeAnnotation); } } }
@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(); }
cdiContainer.getContextControl().startContext(SessionScoped.class); cdiContainer.getContextControl().startContext(RequestScoped.class); Assert.assertEquals("tck-tester", testUser.getName()); cdiContainer.getContextControl().stopContext(RequestScoped.class); cdiContainer.getContextControl().startContext(RequestScoped.class);
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 stop() { if (container != null && isValid) { LOG.debug("stopping OpenWebBeans container"); container.getContextControl().stopContexts(); container.shutdown(); unsetProbeClassLoader(); } }
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(); }
ctxCtrl.stopContext(ConversationScoped.class); ctxCtrl.stopContext(RequestScoped.class); ctxCtrl.stopContext(SessionScoped.class); ctxCtrlBean.destroy(ctxCtrl, ctxCtrlCreationalContext);