private void stopConversationContext() { if(conversationContext.get() != null) { conversationContext.get().destroy(); } conversationContext.set(null); conversationContext.remove(); }
if (conversationId.equals(conversationContext.getConversation().getId())) if (conversationContext.getConversation().iUseIt() > 1) conversationContext.getConversation().getId() + " is used by other request. It creates a new transient conversation"); conversationContext.getConversation().setProblemDuringCreation(problem); conversationContext.setActive(true); return conversationContext; ConversationContext conversationContext = new ConversationContext(webBeansContext); conversationContext.setActive(true); conversationContext.getConversation().setProblemDuringCreation(problem);
/** * Initialize conversation context. * * @param context context */ private void initConversationContext(final ConversationContext context) { if (webBeansContext.getService(ConversationService.class) == null) { return; } if (context == null) { if (conversationContext.get() == null) { final ConversationContext newContext = new ConversationContext(); newContext.setActive(true); conversationContext.set(newContext); } else { conversationContext.get().setActive(true); } } else { context.setActive(true); conversationContext.set(context); } }
private void startConversationContext() { ConversationManager conversationManager = webBeansContext.getConversationManager(); ConversationContext ctx = conversationManager.getConversationContext(getCurrentSessionContext()); ctx.setActive(true); conversationContext.set(ctx); if (ctx.getConversation().isTransient()) { webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent( conversationManager.getLifecycleEventPayload(ctx), InitializedLiteral.INSTANCE_CONVERSATION_SCOPED); } }
/** * {@inheritDoc} */ @Override protected ConversationImpl newInstance(CreationalContextImpl<ConversationImpl> creationalContext) { Context currentContext = contextsService.getCurrentContext(ConversationScoped.class); if (currentContext != null && currentContext instanceof ConversationContext) { return ((ConversationContext) currentContext).getConversation(); } else { throw new ContextNotActiveException("WebBeans context with scope type annotation @ConversationScoped" + " does not exist within current thread"); } } }
/** * Initialize conversation context. * @param startObject either a ServletRequest or a ConversationContext */ protected void initConversationContext(Object startObject) { if (conversationContexts.get() != null) { return; } if (startObject instanceof ConversationContext) { //X TODO check if this branch is still needed ConversationContext context = (ConversationContext) startObject; context.setActive(true); conversationContexts.set(context); } }
public Object getLifecycleEventPayload(ConversationContext ctx) { Object payLoad = null; if (ctx.getConversation().getId() != null) { payLoad = ctx.getConversation().getId(); } if (payLoad == null) { RequestContext requestContext = (RequestContext) webBeansContext.getContextsService().getCurrentContext(RequestScoped.class); if (requestContext != null) { payLoad = requestContext.getRequestObject(); } } if (payLoad == null) { payLoad = new Object(); } return payLoad; }
/** * Destroy conversation context. */ private void destroyConversationContext() { if (webBeansContext.getService(ConversationService.class) == null) { return; } final ConversationContext context = getConversationContext(); if (context != null) { context.destroy(); } if (null != conversationContext) { conversationContext.set(null); conversationContext.remove(); } }
/** * Add the given ConversationContext to the SessionContext. * This method usually will get called at {@link Conversation#begin()}. */ public void addToConversationStorage(ConversationContext conversationContext, String conversationId) { Asserts.assertNotNull(conversationId, "conversationId"); Context sessionContext = webBeansContext.getContextsService().getCurrentContext(SessionScoped.class); Set<ConversationContext> sessionConversations = getSessionConversations(sessionContext, true); // check whether this conversation already exists for (ConversationContext sessionConversation : sessionConversations) { if (conversationId.equals(sessionConversation.getConversation().getId())) { throw new IllegalArgumentException("Conversation with id=" + conversationId + " already exists!"); } } // if not, then simply add this conversation sessionConversations.add(conversationContext); }
/** * Destroy conversation context. */ protected void destroyConversationContext() { if (conversationContexts.get() == null) { return; } ConversationContext context = getConversationContext(false, true); if (context != null) { context.destroy(); webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent( new Object(), DestroyedLiteral.INSTANCE_SINGLETON_SCOPED); } conversationContexts.set(null); conversationContexts.remove(); }
/** * Get current conversation ctx. * @return conversation context */ public ConversationContext getConversationContext(boolean create, boolean ignoreProblems) { ConversationContext conversationContext = conversationContexts.get(); if (conversationContext == null) { SessionContext sessionContext = getSessionContext(create); if (sessionContext != null) { conversationContext = conversationManager.getConversationContext(sessionContext); conversationContexts.set(conversationContext); if (conversationContext.getConversation().isTransient()) { webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent( conversationManager.getLifecycleEventPayload(conversationContext), InitializedLiteral.INSTANCE_CONVERSATION_SCOPED); } if (!ignoreProblems && conversationContext.getConversation().getProblemDuringCreation() != null) { throw conversationContext.getConversation().getProblemDuringCreation(); } } } return conversationContext; }
@Override public void destroy(Object destroyObject) { RequestContext requestCtx = requestContext.get(); if (requestCtx != null) { requestCtx.destroy(); RequestScopedBeanInterceptorHandler.removeThreadLocals(); requestContext.set(null); requestContext.remove(); } SessionContext sessionCtx = sessionContext.get(); if (sessionCtx != null) { sessionCtx.destroy(); SessionScopedBeanInterceptorHandler.removeThreadLocals(); sessionContext.set(null); sessionContext.remove(); } ConversationContext conversationCtx = conversationContext.get(); if (conversationCtx != null) { conversationCtx.destroy(); conversationContext.set(null); conversationContext.remove(); } dependentContext.set(null); dependentContext.remove(); destroyGlobalContexts(); }
ConversationImpl conv = conversationContext.getConversation(); if (conversationManager.conversationTimedOut(conv)) currentConversationContext.getConversation().iDontUseItAnymore(); if (currentConversationContext.getConversation().isTransient())
if (conversationCtx != null) conversationCtx.destroy(); conversationContexts.set(null); conversationContexts.remove();
private Context getCurrentConversationContext() { ConversationContext conversationCtx = conversationContext.get(); if (conversationCtx == null) { conversationCtx = webBeansContext.getConversationManager().getConversationContext(getCurrentSessionContext()); conversationContext.set(conversationCtx); // check for busy and non-existing conversations String conversationId = webBeansContext.getConversationService().getConversationId(); if (conversationId != null && conversationCtx.getConversation().isTransient()) { throw new NonexistentConversationException("Propogated conversation with cid=" + conversationId + " cannot be restored. It creates a new transient conversation."); } if (conversationCtx.getConversation().iUseIt() > 1) { //Throw Busy exception throw new BusyConversationException("Propogated conversation with cid=" + conversationId + " is used by other request. It creates a new transient conversation"); } } return conversationCtx; }
/** * {@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()); } // ensure session ThreadLocal is set webBeansContext.getContextsService().startContext(SessionScoped.class, event.getSession()); webBeansContext.getContextsService().endContext(SessionScoped.class, event.getSession()); if (WebappWebBeansContext.class.isInstance(webBeansContext)) { // end after child WebappWebBeansContext.class.cast(webBeansContext).getParent().getContextsService().endContext(SessionScoped.class, event.getSession()); } final ConversationManager conversationManager = webBeansContext.getConversationManager(); final Map<Conversation, ConversationContext> cc = conversationManager.getAndRemoveConversationMapWithSessionId(event.getSession().getId()); for (final ConversationContext c : cc.values()) { if (c != null) { c.destroy(); } } destroyFakedRequest(); }
/** * Destroy the given ConversationContext and fire the proper * @Destroyed event with the correct payload. */ public void destroyConversationContext(ConversationContext ctx) { webBeansContext.getBeanManagerImpl().fireEvent( getLifecycleEventPayload(ctx), BeforeDestroyedLiteral.INSTANCE_CONVERSATION_SCOPED); ctx.destroy(); webBeansContext.getBeanManagerImpl().fireEvent( getLifecycleEventPayload(ctx), DestroyedLiteral.INSTANCE_CONVERSATION_SCOPED); }