public void destroy(final Object destroyObject) { super.destroy(destroyObject); removeThreadLocals(); }
@Override public Context getCurrentContext(final Class<? extends Annotation> scopeType) { if (scopeType.equals(RequestScoped.class)) { return getRequestContext(); } else if (scopeType.equals(SessionScoped.class)) { return getSessionContext(); } else if (scopeType.equals(ApplicationScoped.class)) { return getApplicationContext(); } else if (supportsConversation() && scopeType.equals(ConversationScoped.class)) { return getConversationContext(); } else if (scopeType.equals(Dependent.class)) { return dependentContext; } else if (scopeType.equals(Singleton.class)) { return getSingletonContext(); } return null; }
public void destroy(final Object destroyObject) { //Destroy application context endContext(ApplicationScoped.class, destroyObject); //Destroy singleton context endContext(Singleton.class, destroyObject); removeThreadLocals(); }
private boolean startRequestScope() { if (service.getRequestContext(false) == null) { service.startContext(RequestScoped.class, getEvent()); return true; } return false; }
private void destroyRequestContext() { // execute request tasks endRequest(); if (supportsConversation()) { // OWB-595 cleanupConversation(); } //Get context final RequestContext context = getRequestContext(); //Destroy context if (context != null) { context.destroy(); } // clean up the EL caches after each request final ELContextStore elStore = ELContextStore.getInstance(false); if (elStore != null) { elStore.destroyELContextStore(); } //Clear thread locals - only for request to let user do with deltaspike start(session, request)restart(request)...stop() requestContext.remove(); RequestScopedBeanInterceptorHandler.removeThreadLocals(); }
@Override public void init(final Object initializeObject) { //Start application context startContext(ApplicationScoped.class, initializeObject); //Start signelton context startContext(Singleton.class, initializeObject); }
webBeansContext.registerService(ContextsService.class, new CdiAppContextsService(webBeansContext, true)); webBeansContext.registerService(ResourceInjectionService.class, new CdiResourceInjectionService(webBeansContext));
@Override public void contextEntered(final ThreadContext oldContext, final ThreadContext newContext) { final BeanContext beanContext = newContext.getBeanContext(); final WebBeansContext webBeansContext = beanContext.getModuleContext().getAppContext().getWebBeansContext(); if (webBeansContext == null) { return; } final ContextsService contextsService = webBeansContext.getContextsService(); final Context requestContext = CdiAppContextsService.class.cast(contextsService).getRequestContext(false); if (requestContext == null) { contextsService.startContext(RequestScoped.class, CdiAppContextsService.EJB_REQUEST_EVENT); newContext.set(DestroyContext.class, new DestroyContext(contextsService, newContext)); } }
private void stopRequestScope() { service.endContext(RequestScoped.class, getEvent()); }
@Override // this method is called after the deployment (BeansDeployer) but need beans to be here to get events public void init(final Object initializeObject) { super.init(initializeObject); if (initializeObject != null) { Object event = initializeObject; if (StartupObject.class.isInstance(initializeObject)) { final StartupObject so = StartupObject.class.cast(initializeObject); if (so.isFromWebApp()) { // ear webapps event = so.getWebContext().getServletContext(); } else if (so.getAppInfo().webAppAlone) { event = SystemInstance.get().getComponent(ServletContext.class); } } else if (ServletContextEvent.class.isInstance(initializeObject)) { event = ServletContextEvent.class.cast(initializeObject).getServletContext(); } if (!FiredManually.class.isInstance(event)) { applicationStarted(event); } } }
/** * {@inheritDoc} */ @Override public void sessionCreated(final HttpSessionEvent event) { try { if (logger.isDebugEnabled()) { logger.debug("Starting a session with session id : [{0}]", event.getSession().getId()); } if (webBeansContext instanceof WebappWebBeansContext) { // start before child ((WebappWebBeansContext) webBeansContext).getParent().getContextsService().startContext(SessionScoped.class, event.getSession()); } contextsService.startContext(SessionScoped.class, event.getSession()); } catch (final Exception e) { logger.error(OWBLogConst.ERROR_0020, event.getSession()); WebBeansUtil.throwRuntimeExceptions(e); } }
services.put(ContextsService.class, new CdiAppContextsService(true)); services.put(ResourceInjectionService.class, new CdiResourceInjectionService()); services.put(ScannerService.class, new CdiScanner());
/** * {@inheritDoc} */ @Override public void sessionDestroyed(final HttpSessionEvent event) { if (webBeansContext == null) { return; } if (logger.isDebugEnabled()) { logger.debug("Destroying a session with session id : [{0}]", event.getSession().getId()); } contextsService.endContext(SessionScoped.class, event.getSession()); WebBeansListenerHelper.destroyFakedRequest(this); }
CdiAppContextsService.class.cast(contextsService).applicationStarted(standardContext.getServletContext());
@Override public void contextExited(final ThreadContext exitedContext, final ThreadContext reenteredContext) { if (exitedContext == null) { return; } final DestroyContext destroyContext = exitedContext.get(DestroyContext.class); if (destroyContext == null || destroyContext.threadContext != exitedContext) { return; } destroyContext.contextsService.endContext(RequestScoped.class, null); CdiAppContextsService.class.cast(destroyContext.contextsService).removeThreadLocals(); }
contextsService.endContext(RequestScoped.class, event); if (webBeansContext instanceof WebappWebBeansContext) { // end after child ((WebappWebBeansContext) webBeansContext).getParent().getContextsService().endContext(RequestScoped.class, event); contextsService.removeThreadLocals(); ThreadSingletonServiceImpl.enter((WebBeansContext) oldContext);
/** * {@inheritDoc} */ @Override public void requestInitialized(final ServletRequestEvent event) { final Object oldContext = ThreadSingletonServiceImpl.enter(this.webBeansContext); if (event != null) { event.getServletRequest().setAttribute(contextKey, oldContext); } try { if (logger.isDebugEnabled()) { logger.debug("Starting a new request : [{0}]", event == null ? "null" : event.getServletRequest().getRemoteAddr()); } if (webBeansContext instanceof WebappWebBeansContext) { // start before child ((WebappWebBeansContext) webBeansContext).getParent().getContextsService().startContext(RequestScoped.class, event); } contextsService.startContext(RequestScoped.class, event); // we don't initialise the Session here but do it lazily if it gets requested // the first time. See OWB-457 } catch (final Exception e) { logger.error(OWBLogConst.ERROR_0019, event == null ? "null" : event.getServletRequest()); WebBeansUtil.throwRuntimeExceptions(e); } }
services.put(ContextsService.class, new CdiAppContextsService(webBeansContext, true)); services.put(ResourceInjectionService.class, new CdiResourceInjectionService(webBeansContext));
@Override public void contextExited(final ThreadContext exitedContext, final ThreadContext reenteredContext) { if (exitedContext == null) { return; } final DestroyContext destroyContext = exitedContext.get(DestroyContext.class); if (destroyContext == null || destroyContext.threadContext != exitedContext) { return; } destroyContext.contextsService.endContext(RequestScoped.class, CdiAppContextsService.EJB_REQUEST_EVENT); CdiAppContextsService.class.cast(destroyContext.contextsService).removeThreadLocals(); }
public static void stopContexts(final ContextsService contextsService, final ServletContext servletContext, final HttpSession session) throws Exception { contextsService.endContext(SessionScoped.class, session); contextsService.endContext(RequestScoped.class, null); contextsService.endContext(ConversationScoped.class, null); if (CdiAppContextsService.class.isInstance(contextsService)) { CdiAppContextsService.class.cast(contextsService).removeThreadLocals(); } } }