myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject svn commit: r549104 - in /myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation: ConversationManager.java jsf/filter/OrchestraServletFilter.java spring/_SpringUtils.java
Date Wed, 20 Jun 2007 13:28:16 GMT
Author: imario
Date: Wed Jun 20 06:28:15 2007
New Revision: 549104

URL: http://svn.apache.org/viewvc?view=rev&rev=549104
Log:
added "serializeRequests" configuration to OrchestraServletFilter with default to "true" which
will serialize requests against the conversationContext to avoid problems in multithreading
environments (e.g. when using ajax)

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/jsf/filter/OrchestraServletFilter.java
    myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/_SpringUtils.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?view=diff&rev=549104&r1=549103&r2=549104
==============================================================================
--- 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 Jun 20 06:28:15 2007
@@ -22,23 +22,17 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.myfaces.orchestra.conversation.spring.ConversationPolicy;
-import org.apache.myfaces.orchestra.conversation.spring._SpringUtils;
 import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapter;
 import org.apache.myfaces.orchestra.requestParameterProvider.RequestParameterProviderManager;
 import org.apache.myfaces.shared_orchestra.util.ClassUtils;
-import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
-import org.springframework.context.ConfigurableApplicationContext;
 
 import javax.faces.FacesException;
-import javax.servlet.http.HttpSession;
 import java.io.IOException;
 import java.io.ObjectStreamException;
 import java.io.Serializable;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
-import java.util.Set;
 
 /**
  * The manager will deal with the various contexts in the current session.
@@ -61,7 +55,7 @@
 
 	private ConversationMessager conversationMessager;
 
-	private Set managedScopes;
+	// private Set managedScopes;
 
 	private class ConversationWiperThread extends Thread
 	{
@@ -99,12 +93,21 @@
 	}
 
 	/**
-	 * Get the conversation manager
+	 * Get the conversation manager. This creates a new one if none exists.
 	 */
 	public static ConversationManager getInstance()
 	{
+		return getInstance(true);
+	}
+
+	/**
+	 * Get the conversation manager.
+	 * @param create false if you just would like to get one if it has been created already
  
+	 */
+	public static ConversationManager getInstance(boolean create)
+	{
 		ConversationManager conversationManager = (ConversationManager) FrameworkAdapter.getInstance().getSessionAttribute(CONVERSATION_MANAGER_KEY);
-		if (conversationManager == null)
+		if (conversationManager == null && create)
 		{
 			conversationManager = createConversationManager();
 
@@ -130,7 +133,7 @@
 
 		// initialize the messager
 		conversationManager.createMessager();
-		conversationManager.managedScopes = _SpringUtils.getConversationManagedScopeNames();
+		// conversationManager.managedScopes = _SpringUtils.getConversationManagedScopeNames();
 
 		return conversationManager;
 	}
@@ -262,7 +265,7 @@
 	 */
 	public Conversation getConversation(String name)
 	{
-		ConversationContext conversationContext = getConversationContext();
+		ConversationContext conversationContext = getCurrentConversationContext();
 		if (conversationContext == null)
 		{
 			return null;
@@ -275,7 +278,7 @@
 	 */
 	public boolean hasConversation(String name)
 	{
-		ConversationContext conversationContext = getConversationContext();
+		ConversationContext conversationContext = getCurrentConversationContext();
 		if (conversationContext == null)
 		{
 			return false;
@@ -285,7 +288,7 @@
 
 	public Iterator iterateConversations()
 	{
-		ConversationContext conversationContext = getConversationContext();
+		ConversationContext conversationContext = getCurrentConversationContext();
 		if (conversationContext == null)
 		{
 			return null;
@@ -299,9 +302,14 @@
 	 *
 	 * @return null if there is no context active
 	 */
-	protected ConversationContext getConversationContext()
+	public ConversationContext getCurrentConversationContext()
 	{
 		Long conversationContextId = getConversationContextId();
+		if (conversationContextId == null)
+		{
+			return null;
+		}
+
 		ConversationContext conversationContext = getConversationContext(conversationContextId);
 		return conversationContext;
 	}
@@ -315,7 +323,7 @@
 			(
 				FrameworkAdapter.getInstance().containsRequestAttribute(CONVERSATION_CONTEXT_REQ) ||
 					FrameworkAdapter.getInstance().containsRequestParameterAttribute(CONVERSATION_CONTEXT_REQ))
&&
-				getConversationContext() != null;
+				getCurrentConversationContext() != null;
 	}
 
 	/**
@@ -390,7 +398,6 @@
 
 	/**
 	 * check if a bean with the given name will be managed by the conversationManager.
-	 */
 	public boolean isManagedBean(String beanName)
 	{
 		ConfigurableApplicationContext applicationContext = FrameworkAdapter.getInstance().getApplicationContext();
@@ -405,6 +412,7 @@
 
 		return beanDefinition.getScope() != null && managedScopes.contains(beanDefinition.getScope());
 	}
+	 */
 
 	private void writeObject(java.io.ObjectOutputStream out) throws IOException
 	{

Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/filter/OrchestraServletFilter.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/filter/OrchestraServletFilter.java?view=diff&rev=549104&r1=549103&r2=549104
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/filter/OrchestraServletFilter.java
(original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/jsf/filter/OrchestraServletFilter.java
Wed Jun 20 06:28:15 2007
@@ -20,6 +20,8 @@
 package org.apache.myfaces.orchestra.conversation.jsf.filter;
 
 import org.apache.myfaces.orchestra.connectionManager.ConnectionManagerDataSource;
+import org.apache.myfaces.orchestra.conversation.ConversationContext;
+import org.apache.myfaces.orchestra.conversation.ConversationManager;
 
 import javax.servlet.Filter;
 import javax.servlet.FilterChain;
@@ -33,11 +35,27 @@
 
 public class OrchestraServletFilter implements Filter
 {
+	/**
+	 * true|false
+	 * Allows to configure if Orchestra should serialize each request against the conversationContext.
+	 * This means, that e.g. if multiple threads (in an ajax environment) concurrently access
the
+	 * conversationContext would not bother each other.
+	 * Default: true
+	 */
+	public final static String SERIALIZE_REQUESTS = "serializeRequests"; // NON-NLS
+
 	private static ThreadLocal httpServletRequest = new ThreadLocal();
 	private static ThreadLocal httpServletResponse = new ThreadLocal();
 
+	private boolean serializeRequests = true;
+
 	public void init(FilterConfig filterConfig) throws ServletException
 	{
+		String value = filterConfig.getInitParameter(SERIALIZE_REQUESTS);
+		if ("false".equals(value)) // NON-NLS
+		{
+			serializeRequests = false;
+		}
 	}
 
 	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain
filterChain) throws IOException, ServletException
@@ -53,7 +71,26 @@
 				httpServletResponse.set(servletResponse);
 			}
 
-			filterChain.doFilter(servletRequest, servletResponse);
+			ConversationContext conversationContext = null;
+			if (serializeRequests)
+			{
+				ConversationManager manager = ConversationManager.getInstance(false);
+				if (manager != null)
+				{
+					conversationContext = manager.getCurrentConversationContext();
+				}
+			}
+			if (serializeRequests && conversationContext != null)
+			{
+				synchronized(conversationContext)
+				{
+					filterChain.doFilter(servletRequest, servletResponse);
+				}
+			}
+			else
+			{
+				filterChain.doFilter(servletRequest, servletResponse);
+			}
 		}
 		finally
 		{

Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/_SpringUtils.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/_SpringUtils.java?view=diff&rev=549104&r1=549103&r2=549104
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/_SpringUtils.java
(original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/spring/_SpringUtils.java
Wed Jun 20 06:28:15 2007
@@ -18,14 +18,6 @@
  */
 package org.apache.myfaces.orchestra.conversation.spring;
 
-import org.apache.myfaces.orchestra.frameworkAdapter.FrameworkAdapter;
-import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
-import org.springframework.beans.factory.config.Scope;
-import org.springframework.context.ConfigurableApplicationContext;
-
-import java.util.Set;
-import java.util.TreeSet;
-
 /**
  * <p>Various Spring utilities used by the conversation framework</p>
  * <p>Notice: this class is not meant to be used outside of this library</p>
@@ -36,6 +28,7 @@
 	{
 	}
 
+	/*
 	public static Set getConversationManagedScopeNames()
 	{
 		ConfigurableApplicationContext applicationContext = FrameworkAdapter.getInstance().getApplicationContext();
@@ -56,4 +49,5 @@
 
 		return managedScopes;
 	}
+	*/
 }



Mime
View raw message