@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); }
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); } } }
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(); }
@Override public void startContext(Class<? extends Annotation> scopeClass) { wrapped.startContext(scopeClass); if (isManuallyHandledRequest(scopeClass)) { for (ExternalContainer externalContainer : CdiTestRunner.getActiveExternalContainers()) { externalContainer.startScope(scopeClass); } } }
@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(); } } };
contextControl.startContext(scopeAnnotation); this.startedScopes.add(scopeAnnotation);
contextControl.startContext(scopeAnnotation); this.startedScopes.add(scopeAnnotation);
cdiContainer.getContextControl().startContext(SessionScoped.class); cdiContainer.getContextControl().startContext(RequestScoped.class); cdiContainer.getContextControl().startContext(RequestScoped.class);