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); } }
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; }
/** * 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; }