Skip to content

Commit

Permalink
[WELD-865]; proper conversation handling, put back -preview.
Browse files Browse the repository at this point in the history
  • Loading branch information
alesj committed Oct 31, 2011
1 parent 8eab748 commit 8cee6b4
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,10 @@
*/
package org.jboss.weld.context;

import org.jboss.weld.Container;
import org.jboss.weld.context.beanstore.BoundBeanStore;
import org.jboss.weld.context.beanstore.ConversationNamingScheme;
import org.jboss.weld.context.beanstore.NamingScheme;
import org.jboss.weld.context.conversation.ConversationIdGenerator;
import org.jboss.weld.context.conversation.ConversationImpl;
import org.jboss.weld.logging.messages.ConversationMessage;
import static org.jboss.weld.context.conversation.ConversationIdGenerator.CONVERSATION_ID_GENERATOR_ATTRIBUTE_NAME;
import static org.jboss.weld.logging.messages.ConversationMessage.NO_CONVERSATION_FOUND_TO_RESTORE;
import static org.jboss.weld.util.reflection.Reflections.cast;

import javax.enterprise.context.ConversationScoped;
import javax.enterprise.inject.Instance;
import java.lang.annotation.Annotation;
import java.util.Collection;
import java.util.HashMap;
Expand All @@ -40,16 +34,24 @@
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import javax.enterprise.context.ConversationScoped;
import javax.enterprise.inject.Instance;

import static org.jboss.weld.context.conversation.ConversationIdGenerator.CONVERSATION_ID_GENERATOR_ATTRIBUTE_NAME;
import static org.jboss.weld.util.reflection.Reflections.cast;
import org.jboss.weld.Container;
import org.jboss.weld.context.beanstore.BoundBeanStore;
import org.jboss.weld.context.beanstore.ConversationNamingScheme;
import org.jboss.weld.context.beanstore.NamingScheme;
import org.jboss.weld.context.conversation.ConversationIdGenerator;
import org.jboss.weld.context.conversation.ConversationImpl;
import org.jboss.weld.logging.messages.ConversationMessage;


/**
* The base of the conversation context, which can use a variety of storage
* forms
*
* @author Pete Muir
* @author George Sapountzis
*/
public abstract class AbstractConversationContext<R, S> extends AbstractBoundContext<R> implements ConversationContext {

Expand Down Expand Up @@ -173,6 +175,59 @@ public void activate() {
this.activate(null);
}

protected void associateRequest() {
ManagedConversation conversation = new ConversationImpl(conversationContexts);
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(ConversationContext.class.getName(), "transient");
setBeanStore(createRequestBeanStore(namingScheme, getRequest()));
setRequestAttribute(getRequest(), ConversationNamingScheme.PARAMETER_NAME, namingScheme);
}

protected void associateRequest(String cid) {
ManagedConversation conversation = getConversation(cid);
setRequestAttribute(getRequest(), CURRENT_CONVERSATION_ATTRIBUTE_NAME, conversation);

NamingScheme namingScheme = new ConversationNamingScheme(ConversationContext.class.getName(), cid);
setBeanStore(createRequestBeanStore(namingScheme, getRequest()));
getBeanStore().attach();
}

public void activate(String cid) {
if (getBeanStore() == null) {
if (!isAssociated()) {
throw new IllegalStateException("Must call associate() before calling activate()");
}
// Activate the context
super.setActive(true);

// Attach the conversation
if (cid != null) {
ManagedConversation conversation = getConversation(cid);
if (conversation != null) {
boolean lock = conversation.lock(getConcurrentAccessTimeout());
if (lock) {
associateRequest(cid);
} else {
// Associate the request with a new transient conversation
associateRequest();
throw new BusyConversationException(ConversationMessage.CONVERSATION_LOCK_TIMEDOUT, cid);
}
} else {
// CDI 6.7.4 we must activate a new transient conversation before we throw the exception
associateRequest();
// Make sure that the conversation already exists
throw new NonexistentConversationException(NO_CONVERSATION_FOUND_TO_RESTORE, cid);
}
} else {
associateRequest();
}
} else {
throw new IllegalStateException("Context is already active");
}
}

@Override
public void deactivate() {
// Disassociate from the current conversation
Expand Down Expand Up @@ -224,39 +279,6 @@ public void deactivate() {
}
}

public void activate(String cid) {
if (getBeanStore() == null) {
if (!isAssociated()) {
throw new IllegalStateException("Must call associate() before calling activate()");
}
// Activate the context
super.setActive(true);

// Attach the conversation
if (cid == null || getConversation(cid) == null) {
ManagedConversation conversation = new ConversationImpl(conversationContexts);
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(ConversationContext.class.getName(), "transient");
setBeanStore(createRequestBeanStore(namingScheme, getRequest()));
setRequestAttribute(getRequest(), ConversationNamingScheme.PARAMETER_NAME, namingScheme);
} else {
setRequestAttribute(getRequest(), CURRENT_CONVERSATION_ATTRIBUTE_NAME, getConversation(cid));
if (getCurrentConversation().lock(getConcurrentAccessTimeout())) {
NamingScheme namingScheme = new ConversationNamingScheme(ConversationContext.class.getName(), cid);
setBeanStore(createRequestBeanStore(namingScheme, getRequest()));
getBeanStore().attach();
} else {
throw new BusyConversationException(ConversationMessage.CONVERSATION_LOCK_TIMEDOUT, cid);
}
}

} else {
throw new IllegalStateException("Context is already active");
}
}

@Override
public void invalidate() {
for (ManagedConversation conversation : getConversations()) {
Expand Down
11 changes: 0 additions & 11 deletions impl/src/main/java/org/jboss/weld/jsf/WeldPhaseListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@
import static org.jboss.weld.logging.Category.JSF;
import static org.jboss.weld.logging.LoggerFactory.loggerFactory;
import static org.jboss.weld.logging.messages.ConversationMessage.CLEANING_UP_TRANSIENT_CONVERSATION;
import static org.jboss.weld.logging.messages.ConversationMessage.NO_CONVERSATION_FOUND_TO_RESTORE;
import static org.jboss.weld.logging.messages.JsfMessage.CLEANING_UP_CONVERSATION;
import static org.jboss.weld.logging.messages.JsfMessage.FOUND_CONVERSATION_FROM_REQUEST;
import static org.jboss.weld.logging.messages.JsfMessage.RESUMING_CONVERSATION;

import java.util.Map;

import javax.enterprise.context.spi.Context;
import javax.enterprise.inject.Instance;
import javax.faces.context.FacesContext;
Expand All @@ -45,8 +43,6 @@

import org.jboss.weld.Container;
import org.jboss.weld.context.ConversationContext;
import org.jboss.weld.context.ManagedConversation;
import org.jboss.weld.context.NonexistentConversationException;
import org.jboss.weld.context.http.HttpConversationContext;
import org.slf4j.cal10n.LocLogger;

Expand Down Expand Up @@ -102,13 +98,6 @@ private void activateConversations(FacesContext facesContext) {
HttpConversationContext conversationContext = instance().select(HttpConversationContext.class).get();
String cid = getConversationId(facesContext, conversationContext);
log.debug(RESUMING_CONVERSATION, cid);
ManagedConversation conversation = conversationContext.getConversation(cid);
if (cid != null && conversation == null) {
// CDI 6.7.4 we must activate a new transient conversation before we throw the exception
conversationContext.activate(null);
// Make sure that the conversation already exists
throw new NonexistentConversationException(NO_CONVERSATION_FOUND_TO_RESTORE, cid);
}

/*
* Don't try to reactivate the ConversationContext if we have already activated it for this request
Expand Down
2 changes: 1 addition & 1 deletion jboss-as/jboss-as-7/build.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Container a number of properties associated with installing Weld into JBoss AS and running the TCK in JBoss AS
#jboss.home=/Users/alesj/projects/as7/as/build/target/jboss-as-7.1.0.Alpha1-SNAPSHOT
#jboss.home=/Users/alesj/java_lib/jboss-as-7.0.2.Final
org.jboss.testharness.container.javaOpts=-Xms128m -Xmx512m -XX:MaxPermSize=256m -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000

# time to allow before attempting to restart JBoss AS
Expand Down
4 changes: 2 additions & 2 deletions jboss-tck-runner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
<suiteXmlFile>src/test/resources/tck-tests.xml</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<jboss.server.config.file.name>standalone.xml</jboss.server.config.file.name>
<jboss.server.config.file.name>standalone-preview.xml</jboss.server.config.file.name>
</systemPropertyVariables>
<systemProperties>
<property>
Expand Down Expand Up @@ -301,7 +301,7 @@
<suiteXmlFile>src/test/resources/tck-tests.xml</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<jboss.server.config.file.name>standalone.xml</jboss.server.config.file.name>
<jboss.server.config.file.name>standalone-preview.xml</jboss.server.config.file.name>
</systemPropertyVariables>
<systemProperties>
<property>
Expand Down

0 comments on commit 8cee6b4

Please sign in to comment.