Refine search
@Override public void invalidate() { ManagedConversation currentConversation = getCurrentConversation(); Map<String, ManagedConversation> conversations = getConversationMap(); synchronized (conversations) { for (Entry<String, ManagedConversation> stringManagedConversationEntry : conversations.entrySet()) { ManagedConversation conversation = stringManagedConversationEntry.getValue(); if (!currentConversation.equals(conversation) && !conversation.isTransient() && isExpired(conversation)) { // Try to lock the conversation and log warning if not successful - unlocking should not be necessary if (!conversation.lock(0)) { ConversationLogger.LOG.endLockedConversation(conversation.getId()); } conversation.end(); } } } }
private static boolean isExpired(ManagedConversation conversation) { return System.currentTimeMillis() > (conversation.getLastUsed() + conversation.getTimeout()); }
@Override public void deactivateContext() { final ConversationState conversationState = CURRENT_CONVERSATION_STATE.get(); final ManagedConversation currentConversation = boundConversationContext.getCurrentConversation(); if (!currentConversation.isTransient() && !conversationState.isLongRunning()) { startLongRunningConversation(conversationState, currentConversation); } else if (currentConversation.isTransient() && conversationState.isLongRunning()) { endLongRunningConversation(conversationState); } else if (currentConversation.getId() != null && !currentConversation.getId().equals(conversationState.getConversationId())) { LOGGER.warn("current conversation id: {} and registered: {}. There shouldn't be two activated conversations", currentConversation.getId(), conversationState.getConversationId()); } boundConversationContext.deactivate(); boundConversationContext.dissociate(CURRENT_BOUND_REQUEST.get()); CURRENT_BOUND_REQUEST.remove(); CURRENT_CONVERSATION_STATE.remove(); }
throw ConversationLogger.LOG.mustCallAssociateBeforeDeactivate(); if (getCurrentConversation().isTransient() && getRequestAttribute(getRequest(), ConversationNamingScheme.PARAMETER_NAME) != null) { getCurrentConversation().touch(); if (!getBeanStore().isAttached()) { throw ConversationLogger.LOG.conversationNamingSchemeNotFound(); .getId()); getConversationMap().put(getCurrentConversation().getId(), getCurrentConversation()); getCurrentConversation().unlock(); throw ConversationLogger.LOG.contextNotActive();
boolean isTransient = conversationContext.getCurrentConversation().isTransient(); if (ConversationLogger.LOG.isTraceEnabled()) { if (isTransient) { ConversationLogger.LOG.cleaningUpTransientConversation(); } else { ConversationLogger.LOG.cleaningUpConversation(conversationContext.getCurrentConversation().getId());
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(); } }
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)); }
/** * Tasks when a long running conversation has started during this event. * * @param conversationState * @param managedConversation */ private void startLongRunningConversation(ConversationState conversationState, ManagedConversation managedConversation) { conversationState.registerLongRunningConversaton(managedConversation.getId()); LOGGER.trace("register long running conversation: {}", managedConversation.getId()); }
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(); } } } }
private boolean lock(ManagedConversation conversation) { return conversation.lock(getConcurrentAccessTimeout()); }
throw ConversationLogger.LOG.mustCallAssociateBeforeDeactivate(); if (getCurrentConversation().isTransient() && getRequestAttribute(getRequest(), ConversationNamingScheme.PARAMETER_NAME) != null) { getCurrentConversation().touch(); if (!getBeanStore().isAttached()) { throw ConversationLogger.LOG.conversationNamingSchemeNotFound(); .getId()); getConversationMap().put(getCurrentConversation().getId(), getCurrentConversation()); getCurrentConversation().unlock(); throw ConversationLogger.LOG.contextNotActive();
boolean isTransient = conversationContext.getCurrentConversation().isTransient(); if (ConversationLogger.LOG.isTraceEnabled()) { if (isTransient) { ConversationLogger.LOG.cleaningUpTransientConversation(); } else { ConversationLogger.LOG.cleaningUpConversation(conversationContext.getCurrentConversation().getId());
/** * Allow the delegate to produce the action URL. If the conversation is * long-running, append the conversation id request parameter to the query * string part of the URL, but only if the request parameter is not already * present. * <p/> * This covers form actions Ajax calls, and redirect URLs (which we want) and * link hrefs (which we don't) * * @see {@link ViewHandler#getActionURL(FacesContext, String)} */ @Override public String getActionURL(FacesContext facesContext, String viewId) { if (contextId == null) { if (facesContext.getAttributes().containsKey(Container.CONTEXT_ID_KEY)) { contextId = (String) facesContext.getAttributes().get(Container.CONTEXT_ID_KEY); } else { contextId = RegistrySingletonProvider.STATIC_INSTANCE; } } String actionUrl = super.getActionURL(facesContext, viewId); final ConversationContext ctx = getConversationContext(contextId); if (ctx!= null && ctx.isActive() && !getSource().equals(Source.BOOKMARKABLE) && !ctx.getCurrentConversation().isTransient()) { return new FacesUrlTransformer(actionUrl, facesContext) .appendConversationIdIfNecessary(getConversationContext(contextId).getParameterName(), ctx.getCurrentConversation().getId()) .getUrl(); } else { return actionUrl; } }
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(); } }
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)); }
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(); }
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(); } } } }
private boolean lock(ManagedConversation conversation) { return conversation.lock(getConcurrentAccessTimeout()); }
throw ConversationLogger.LOG.mustCallAssociateBeforeDeactivate(); if (getCurrentConversation().isTransient() && getRequestAttribute(getRequest(), ConversationNamingScheme.PARAMETER_NAME) != null) { getCurrentConversation().touch(); if (!getBeanStore().isAttached()) { throw ConversationLogger.LOG.conversationNamingSchemeNotFound(); .getId()); getConversationMap().put(getCurrentConversation().getId(), getCurrentConversation()); getCurrentConversation().unlock(); throw ConversationLogger.LOG.contextNotActive();
@Override public void invalidate() { ManagedConversation currentConversation = getCurrentConversation(); Map<String, ManagedConversation> conversations = getConversationMap(); synchronized (conversations) { for (Entry<String, ManagedConversation> stringManagedConversationEntry : conversations.entrySet()) { ManagedConversation conversation = stringManagedConversationEntry.getValue(); if (!currentConversation.equals(conversation) && !conversation.isTransient() && isExpired(conversation)) { // Try to lock the conversation and log warning if not successful - unlocking should not be necessary if (!conversation.lock(0)) { ConversationLogger.LOG.endLockedConversation(conversation.getId()); } conversation.end(); } } } }