You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by im...@apache.org on 2008/04/03 08:58:45 UTC
svn commit: r644188 - in
/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra:
conversation/ConversationManager.java
conversation/ConversationRequestParameterProvider.java
lib/jsf/ContextLockRequestHandler.java
Author: imario
Date: Wed Apr 2 23:58:43 2008
New Revision: 644188
URL: http://svn.apache.org/viewvc?rev=644188&view=rev
Log:
allow to eagerly create the conversationContext
Modified:
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationManager.java
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationRequestParameterProvider.java
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/ContextLockRequestHandler.java
Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationManager.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationManager.java?rev=644188&r1=644187&r2=644188&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationManager.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationManager.java Wed Apr 2 23:58:43 2008
@@ -19,6 +19,11 @@
package org.apache.myfaces.orchestra.conversation;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapter;
+import org.apache.myfaces.orchestra.requestParameterProvider.RequestParameterProviderManager;
+
import java.io.IOException;
import java.io.ObjectStreamException;
import java.io.Serializable;
@@ -27,11 +32,6 @@
import java.util.Iterator;
import java.util.Map;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapter;
-import org.apache.myfaces.orchestra.requestParameterProvider.RequestParameterProviderManager;
-
/**
* Deals with the various conversation contexts in the current session.
* <p>
@@ -62,14 +62,14 @@
* on the same webapp within the same HttpSession. Note that this is a
* property of an object stored in the session, so will correctly
* migrate from machine to machine along with a distributed HttpSession.
- *
+ *
*/
private long nextConversationContextId = 1;
// This member must always be accessed with a lock held on the parent ConverstationManager instance;
// a HashMap is not thread-safe and this class must be thread-safe.
private final Map conversationContexts = new HashMap();
-
+
protected ConversationManager()
{
}
@@ -235,8 +235,7 @@
*/
public Conversation startConversation(String name, ConversationFactory factory)
{
- Long conversationContextId = getConversationContextId();
- ConversationContext conversationContext = getOrCreateConversationContext(conversationContextId);
+ ConversationContext conversationContext = getCurrentConversationContext(true);
return conversationContext.startConversation(name, factory);
}
@@ -302,14 +301,26 @@
/**
* Get the current conversation context.
- *
- * @return null if there is no context active
*/
- public ConversationContext getCurrentConversationContext()
+ public ConversationContext getCurrentConversationContext(boolean create)
{
Long conversationContextId = getConversationContextId();
ConversationContext conversationContext = getConversationContext(conversationContextId);
+ if (conversationContext == null && create)
+ {
+ conversationContext = getOrCreateConversationContext(conversationContextId);
+ }
return conversationContext;
+ }
+
+ /**
+ * Get the current conversation context.
+ *
+ * @return null if there is no context active
+ */
+ public ConversationContext getCurrentConversationContext()
+ {
+ return getCurrentConversationContext(false);
}
/**
Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationRequestParameterProvider.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationRequestParameterProvider.java?rev=644188&r1=644187&r2=644188&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationRequestParameterProvider.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationRequestParameterProvider.java Wed Apr 2 23:58:43 2008
@@ -46,7 +46,7 @@
* response page should have the special ConversationContext query
* parameter added to them or not.
* <p>
- * Defaults to false (no separation), which means that urls ARE modified.
+ * Defaults to false (no separation), which means that urls ARE modified.
* <p>
* This can be called by a component before rendering its children in order to
* skip this url mangling. Any code that calls this method is responsible for
@@ -83,13 +83,9 @@
throw new IllegalStateException("can find the conversationManager");
}
- Long conversationContextId = conversationManager.getConversationContextId();
- if (conversationContextId == null)
- {
- return null;
- }
+ ConversationContext ctx = conversationManager.getCurrentConversationContext(true);
- return Long.toString(conversationContextId.longValue(), Character.MAX_RADIX);
+ return Long.toString(ctx.getId(), Character.MAX_RADIX);
}
public String[] getFields()
Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/ContextLockRequestHandler.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/ContextLockRequestHandler.java?rev=644188&r1=644187&r2=644188&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/ContextLockRequestHandler.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/lib/jsf/ContextLockRequestHandler.java Wed Apr 2 23:58:43 2008
@@ -18,20 +18,19 @@
*/
package org.apache.myfaces.orchestra.lib.jsf;
-import java.util.Map;
+import org.apache.myfaces.orchestra.CoreConfig;
+import org.apache.myfaces.orchestra.conversation.ConversationContext;
+import org.apache.myfaces.orchestra.conversation.ConversationManager;
import javax.faces.FacesException;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
-
-import org.apache.myfaces.orchestra.CoreConfig;
-import org.apache.myfaces.orchestra.conversation.ConversationContext;
-import org.apache.myfaces.orchestra.conversation.ConversationManager;
+import java.util.Map;
/**
* RequestHandler that ensures that only one thread is processing
* each ConversationContext at a time.
- *
+ *
* @since 1.1
*/
class ContextLockRequestHandler implements RequestHandler
@@ -49,17 +48,14 @@
ConversationManager manager = ConversationManager.getInstance(false);
if (manager != null)
{
- context = manager.getCurrentConversationContext();
- if (context != null)
+ context = manager.getCurrentConversationContext(true);
+ try
{
- try
- {
- context.lockInterruptablyForCurrentThread();
- }
- catch(InterruptedException e)
- {
- throw new FacesException(e);
- }
+ context.lockInterruptablyForCurrentThread();
+ }
+ catch(InterruptedException e)
+ {
+ throw new FacesException(e);
}
}
}
@@ -72,7 +68,7 @@
context.unlockForCurrentThread();
}
}
-
+
private boolean getSerializeRequests(FacesContext facesContext)
{
ExternalContext ec = facesContext.getExternalContext();
@@ -85,7 +81,7 @@
return serializeRequests.booleanValue();
}
- // Check for the normal global init param; true unless "false" is specified
+ // Check for the normal global init param; true unless "false" is specified
String value = ec.getInitParameter(CoreConfig.SERIALIZE_REQUESTS);
return !"false".equals(value); // NON-NLS
}