/** * {@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"); } } }
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; }
/** * 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); }
/** * 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; }
ConversationImpl conv = conversationContext.getConversation(); if (conversationManager.conversationTimedOut(conv)) currentConversationContext.getConversation().iDontUseItAnymore(); if (currentConversationContext.getConversation().isTransient())
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.getConversation().setProblemDuringCreation(problem);
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; }
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); } }