@Override public ManagedConversation getCurrentConversation() { checkIsAssociated(); checkContextInitialized(); R request = getRequest(); Object attribute = getRequestAttribute(request, CURRENT_CONVERSATION_ATTRIBUTE_NAME); if (attribute == null || !(attribute instanceof ManagedConversation)) { throw ConversationLogger.LOG.unableToLoadCurrentConversation(CURRENT_CONVERSATION_ATTRIBUTE_NAME, attribute, request); } return (ManagedConversation) attribute; }
private void cleanUpConversationMap() { Map<String, ManagedConversation> conversations = getConversationMap(); synchronized (conversations) { Iterator<Entry<String, ManagedConversation>> entryIterator = conversations.entrySet().iterator(); S session = getSessionFromRequest(getRequest(), false); while (entryIterator.hasNext()) { Entry<String, ManagedConversation> entry = entryIterator.next(); if (entry.getValue().isTransient()) { destroyConversation(session, entry.getKey()); entryIterator.remove(); } } } }
protected void copyConversationIdGeneratorAndConversationsToSession() { final R request = getRequest(); if(request == null) { return; } // If necessary, store the conversation id generator and conversation map in the session Object conversationIdGenerator = getRequestAttribute(request, CONVERSATION_ID_GENERATOR_ATTRIBUTE_NAME); if(conversationIdGenerator != null && getSessionAttribute(request, CONVERSATION_ID_GENERATOR_ATTRIBUTE_NAME, false) == null) { setSessionAttribute(request, CONVERSATION_ID_GENERATOR_ATTRIBUTE_NAME, conversationIdGenerator, false); } Object conversationMap = getRequestAttribute(request, CONVERSATIONS_ATTRIBUTE_NAME); if(conversationMap != null && getSessionAttribute(request, CONVERSATIONS_ATTRIBUTE_NAME, false) == null) { setSessionAttribute(request, CONVERSATIONS_ATTRIBUTE_NAME, conversationMap, false); } }
protected void associateRequestWithNewConversation() { ManagedConversation conversation = new ConversationImpl(manager); lock(conversation); setRequestAttribute(getRequest(), CURRENT_CONVERSATION_ATTRIBUTE_NAME, conversation); // Set a temporary bean store, this will be attached at the end of the request if needed NamingScheme namingScheme = new ConversationNamingScheme(getNamingSchemePrefix(), "transient", beanIdentifierIndex); setBeanStore(createRequestBeanStore(namingScheme, getRequest())); setRequestAttribute(getRequest(), ConversationNamingScheme.PARAMETER_NAME, namingScheme); }
private Map<String, ManagedConversation> getConversationMap() { checkIsAssociated(); checkContextInitialized(); final R request = getRequest(); Object conversationMap = getRequestAttribute(request, CONVERSATIONS_ATTRIBUTE_NAME); if(conversationMap == null) { conversationMap = getSessionAttribute(request, CONVERSATIONS_ATTRIBUTE_NAME, false); if (conversationMap == null) { conversationMap = Collections.synchronizedMap(new HashMap<String, ManagedConversation>()); setRequestAttribute(request, CONVERSATIONS_ATTRIBUTE_NAME, conversationMap); setSessionAttribute(request, CONVERSATIONS_ATTRIBUTE_NAME, conversationMap, false); } else { setRequestAttribute(request, CONVERSATIONS_ATTRIBUTE_NAME, conversationMap); } } if (conversationMap == null || !(conversationMap instanceof Map)) { throw ConversationLogger.LOG.unableToLoadConversations(CONVERSATIONS_ATTRIBUTE_NAME, conversationMap, request); } return cast(conversationMap); }
private void setDestructionQueue(Map<String, ManagedConversation> conversations, S session) { Map<String, List<ContextualInstance<?>>> contexts = new HashMap<>(); for (Entry<String, ManagedConversation> entry : conversations.entrySet()) { ManagedConversation conversation = entry.getValue(); // First make all conversations transient if (!conversation.isTransient()) { conversation.end(); } // Extract contextual instances List<ContextualInstance<?>> contextualInstances = new ArrayList<>(); for (String id : new ConversationNamingScheme(getNamingSchemePrefix(), entry.getKey(), beanIdentifierIndex) .filterIds(getSessionAttributeNames(session))) { contextualInstances.add((ContextualInstance<?>) getSessionAttributeFromSession(session, id)); } contexts.put(entry.getKey(), contextualInstances); } // Store remaining conversation contexts for later destruction setRequestAttribute(getRequest(), DESTRUCTION_QUEUE_ATTRIBUTE_NAME, Collections.synchronizedMap(contexts)); }
if (getCurrentConversation().isTransient() && getRequestAttribute(getRequest(), ConversationNamingScheme.PARAMETER_NAME) != null) { if (!(getRequestAttribute(getRequest(), ConversationNamingScheme.PARAMETER_NAME) instanceof ConversationNamingScheme)) { throw ConversationLogger.LOG.conversationNamingSchemeNotFound(); ((ConversationNamingScheme) getRequestAttribute(getRequest(), ConversationNamingScheme.PARAMETER_NAME)).setCid(getCurrentConversation() .getId());
protected void associateRequest(ManagedConversation conversation) { setRequestAttribute(getRequest(), CURRENT_CONVERSATION_ATTRIBUTE_NAME, conversation); NamingScheme namingScheme = new ConversationNamingScheme(getNamingSchemePrefix(), conversation.getId(), beanIdentifierIndex); setBeanStore(createRequestBeanStore(namingScheme, getRequest())); getBeanStore().attach(); }
@Override public void activate(String cid) { if (!isAssociated()) { throw ConversationLogger.LOG.mustCallAssociateBeforeActivate(); } if (!isActive()) { super.setActive(true); } else { ConversationLogger.LOG.contextAlreadyActive(getRequest()); } initialize(cid); }