@Override public void activate() { this.activate(null); }
@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; }
@Override public boolean dissociate(R request) { if (isAssociated()) { try { copyConversationIdGeneratorAndConversationsToSession(); return true; } finally { this.associated.set(null); cleanup(); } } else { return 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); }
if (isActive()) { if (!isAssociated()) { throw ConversationLogger.LOG.mustCallAssociateBeforeDeactivate(); if (getCurrentConversation().isTransient() && getRequestAttribute(getRequest(), ConversationNamingScheme.PARAMETER_NAME) != null) { destroy(); } else { getCurrentConversation().touch(); if (!getBeanStore().isAttached()) { if (!(getRequestAttribute(getRequest(), ConversationNamingScheme.PARAMETER_NAME) instanceof ConversationNamingScheme)) { throw ConversationLogger.LOG.conversationNamingSchemeNotFound(); ((ConversationNamingScheme) getRequestAttribute(getRequest(), ConversationNamingScheme.PARAMETER_NAME)).setCid(getCurrentConversation() .getId()); getBeanStore().attach(); getConversationMap().put(getCurrentConversation().getId(), getCurrentConversation()); getCurrentConversation().unlock(); setBeanStore(null); cleanUpConversationMap(); removeState();
public boolean destroy(S session) { final BoundBeanStore beanStore = getBeanStore(); final boolean active = isActive(); if (beanStore != null) { beanStore.detach(); Object conversationMap = getSessionAttributeFromSession(session, CONVERSATIONS_ATTRIBUTE_NAME); if (conversationMap instanceof Map) { Map<String, ManagedConversation> conversations = cast(conversationMap); if (!conversations.isEmpty()) { setActive(true); if (beanStore == null) { destroyConversation(session, entry.getKey()); setDestructionQueue(conversations, session); setBeanStore(beanStore); setActive(active); if (beanStore != null) { beanStore.attach(); } else if (!active) { removeState(); cleanup();
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); }
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(); }
protected void initialize(String cid) { // Attach the conversation // WELD-1315 Don't try to restore the long-running conversation if cid param is empty if (cid != null && !cid.isEmpty()) { ManagedConversation conversation = getConversation(cid); if (conversation != null && !isExpired(conversation)) { boolean lock = lock(conversation); if (lock) { // WELD-1690 Don't associate a conversation which was ended (race condition) if (conversation.isTransient()) { associateRequestWithNewConversation(); throw ConversationLogger.LOG.noConversationFoundToRestore(cid); } associateRequest(conversation); } else { // CDI 6.7.4 we must activate a new transient conversation before we throw the exception associateRequestWithNewConversation(); throw ConversationLogger.LOG.conversationLockTimedout(cid); } } else { // CDI 6.7.4 we must activate a new transient conversation before we throw the exception associateRequestWithNewConversation(); throw ConversationLogger.LOG.noConversationFoundToRestore(cid); } } else { associateRequestWithNewConversation(); } }
@Override public String generateConversationId() { ConversationIdGenerator generator = getConversationIdGenerator(); checkContextInitialized(); return generator.call(); }
private void notifyConversationContext() { ConversationContext context = getActiveConversationContext(); if (context instanceof AbstractConversationContext) { AbstractConversationContext<?, ?> abstractConversationContext = (AbstractConversationContext<?, ?>) context; abstractConversationContext.conversationPromotedToLongRunning(this); } }
public void sessionCreated() { copyConversationIdGeneratorAndConversationsToSession(); }
if (isActive()) { if (!isAssociated()) { throw ConversationLogger.LOG.mustCallAssociateBeforeDeactivate(); if (getCurrentConversation().isTransient() && getRequestAttribute(getRequest(), ConversationNamingScheme.PARAMETER_NAME) != null) { destroy(); } else { getCurrentConversation().touch(); if (!getBeanStore().isAttached()) { if (!(getRequestAttribute(getRequest(), ConversationNamingScheme.PARAMETER_NAME) instanceof ConversationNamingScheme)) { throw ConversationLogger.LOG.conversationNamingSchemeNotFound(); ((ConversationNamingScheme) getRequestAttribute(getRequest(), ConversationNamingScheme.PARAMETER_NAME)).setCid(getCurrentConversation() .getId()); getBeanStore().attach(); getConversationMap().put(getCurrentConversation().getId(), getCurrentConversation()); getCurrentConversation().unlock(); setBeanStore(null); cleanUpConversationMap(); removeState();
public boolean destroy(S session) { final BoundBeanStore beanStore = getBeanStore(); final boolean active = isActive(); if (beanStore != null) { beanStore.detach(); Object conversationMap = getSessionAttributeFromSession(session, CONVERSATIONS_ATTRIBUTE_NAME); if (conversationMap instanceof Map) { Map<String, ManagedConversation> conversations = cast(conversationMap); if (!conversations.isEmpty()) { setActive(true); if (beanStore == null) { destroyConversation(session, entry.getKey()); setDestructionQueue(conversations, session); setBeanStore(beanStore); setActive(active); if (beanStore != null) { beanStore.attach(); } else if (!active) { removeState(); cleanup();
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); }
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(); }
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); }
protected void initialize(String cid) { // Attach the conversation // WELD-1315 Don't try to restore the long-running conversation if cid param is empty if (cid != null && !cid.isEmpty()) { ManagedConversation conversation = getConversation(cid); if (conversation != null && !isExpired(conversation)) { boolean lock = lock(conversation); if (lock) { // WELD-1690 Don't associate a conversation which was ended (race condition) if (conversation.isTransient()) { associateRequestWithNewConversation(); throw ConversationLogger.LOG.noConversationFoundToRestore(cid); } associateRequest(conversation); } else { // CDI 6.7.4 we must activate a new transient conversation before we throw the exception associateRequestWithNewConversation(); throw ConversationLogger.LOG.conversationLockTimedout(cid); } } else { // CDI 6.7.4 we must activate a new transient conversation before we throw the exception associateRequestWithNewConversation(); throw ConversationLogger.LOG.noConversationFoundToRestore(cid); } } else { associateRequestWithNewConversation(); } }
@Override public String generateConversationId() { ConversationIdGenerator generator = getConversationIdGenerator(); checkContextInitialized(); return generator.call(); }
private void notifyConversationContext() { ConversationContext context = getActiveConversationContext(); if (context instanceof AbstractConversationContext) { AbstractConversationContext<?, ?> abstractConversationContext = (AbstractConversationContext<?, ?>) context; abstractConversationContext.conversationPromotedToLongRunning(this); } }