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 2006/06/22 13:53:39 UTC
svn commit: r416338 -
/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/
Author: imario
Date: Thu Jun 22 04:53:38 2006
New Revision: 416338
URL: http://svn.apache.org/viewvc?rev=416338&view=rev
Log:
Add purgePersistence to inform the PersistenceManager that something went wrong.
Its assumed that the PersistenceManager will throw away its session (in case of hibernate)
Modified:
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationServletFilter.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EndConversationMethodBindingFacade.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManager.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIEnsureConversation.java
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java?rev=416338&r1=416337&r2=416338&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationContext.java Thu Jun 22 04:53:38 2006
@@ -25,23 +25,23 @@
import org.apache.commons.logging.LogFactory;
/**
- * The ConversationContext handles all conversations within the current context
- *
- * @author imario@apache.org
+ * The ConversationContext handles all conversations within the current context
+ *
+ * @author imario@apache.org
*/
public class ConversationContext
{
private final static Log log = LogFactory.getLog(ConversationContext.class);
-
+
private final long id;
-
+
private final Object mutex = new Object();
private final Map conversations = new TreeMap();
private final List conversationStack = new ArrayList(10);
private Conversation currentConversation;
-
+
private long lastAccess;
-
+
protected ConversationContext(long id)
{
this.id = id;
@@ -52,7 +52,7 @@
{
lastAccess = System.currentTimeMillis();
}
-
+
public long getLastAccess()
{
return lastAccess;
@@ -68,15 +68,15 @@
Conversation conversation = (Conversation) iterConversation.next();
conversation.endConversation(false);
}
-
+
conversations.clear();
- conversationStack.clear();
+ conversationStack.clear();
}
}
-
+
/**
* Start a conversation if not already started.<br />
- * All nested conversations (if any) are closed if the conversation already existed.
+ * All nested conversations (if any) are closed if the conversation already existed.
* @param name
*/
public void startConversation(String name, boolean persistence)
@@ -100,7 +100,7 @@
}
/**
- * Ends all conversations nested under conversation
+ * Ends all conversations nested under conversation
*/
protected void endNestedConversations(Conversation conversation, boolean regularEnd)
{
@@ -115,7 +115,7 @@
{
return;
}
-
+
endConversation((Conversation) conversationStack.remove(index), regularEnd);
}
}
@@ -133,7 +133,7 @@
conversations.remove(conversation.getName());
}
}
-
+
/**
* End the conversation with given name.<br />
* This also automatically closes all nested conversations.
@@ -163,7 +163,7 @@
}
}
}
-
+
/**
* Get the current conversation. The current conversation is the one last seen by the startConversation tag.
*/
@@ -198,7 +198,7 @@
}
/**
- * get a conversation by name
+ * get a conversation by name
*/
public Conversation getConversation(String name)
{
@@ -210,11 +210,11 @@
}
/**
- * inject all beans from the conversation context to their configured scope
+ * inject all beans from the conversation context to their configured scope
protected void injectConversationBeans(FacesContext context)
{
Set alreadyAdded = new TreeSet(new ValueBindingKey());
-
+
for (int i = conversationStack.size(); i>0; i--)
{
Conversation conversation = (Conversation) conversationStack.get(i-1);
@@ -247,7 +247,7 @@
return conversation.getBean(name);
}
}
-
+
return null;
}
}
@@ -268,7 +268,7 @@
return conversation.getPersistenceManager();
}
}
-
+
return null;
}
}
@@ -287,6 +287,25 @@
if (conversation.isPersistence())
{
conversation.getPersistenceManager().detach();
+ }
+ }
+ }
+ }
+
+ /**
+ * detach all conversations from their underlaying persistence
+ */
+ public void purgePersistence()
+ {
+ synchronized (mutex)
+ {
+ touch();
+ for (int i = conversationStack.size(); i>0; i--)
+ {
+ Conversation conversation = (Conversation) conversationStack.get(i-1);
+ if (conversation.isPersistence())
+ {
+ conversation.getPersistenceManager().purge();
}
}
}
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java?rev=416338&r1=416337&r2=416338&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationManager.java Thu Jun 22 04:53:38 2006
@@ -31,26 +31,26 @@
/**
* The manager will deal with the various contexts in the current session.
* A new context will be created if the current window has none associated.
- *
- * @author imario@apache.org
+ *
+ * @author imario@apache.org
*/
public class ConversationManager
{
private final static Log log = LogFactory.getLog(ConversationManager.class);
-
+
public final static String CONVERSATION_CONTEXT_PARAM = "conversationContext";
-
+
private final static String INIT_PERSISTENCE_MANAGER_FACOTRY = "org.apache.myfaces.conversation.PERSISTENCE_MANAGER_FACTORY";
private final static String INIT_MESSAGER = "org.apache.myfaces.conversation.MESSAGER";
private final static String CONVERSATION_MANAGER_KEY = "org.apache.myfaces.ConversationManager";
private final static String CONVERSATION_CONTEXT_REQ = "org.apache.myfaces.ConversationManager.conversationContext";
-
- private static long NEXT_CONVERSATION_CONTEXT = 1;
+
+ private static long NEXT_CONVERSATION_CONTEXT = 1;
private PersistenceManagerFactory persistenceManagerFactory;
private ConversationMessager conversationMessager;
-
+
private final Map conversationContexts = new HashMap();
// private final List registeredEndConversations = new ArrayList(10);
@@ -69,7 +69,7 @@
while (!isInterrupted())
{
checkContextTimeout();
-
+
try
{
Thread.sleep(CHECK_TIME);
@@ -81,8 +81,8 @@
}
}
}
- private ContextWiperThread wiperThread = new ContextWiperThread();
-
+ private ContextWiperThread wiperThread = new ContextWiperThread();
+
protected ConversationManager()
{
wiperThread.start();
@@ -100,7 +100,7 @@
}
return getInstance(context);
}
-
+
/**
* Get the conversation manager
*/
@@ -122,7 +122,7 @@
// set mark
context.getExternalContext().getSessionMap().put(CONVERSATION_MANAGER_KEY, conversationManager);
}
-
+
return conversationManager;
}
@@ -150,17 +150,17 @@
}
return (ConversationManager) session.getAttribute(CONVERSATION_MANAGER_KEY);
}
-
+
/**
* Get the current, or create a new unique conversationContextId.<br />
* The current conversationContextId will retrieved from the request parameters, if we cant find it there
- * a new one will be created. In either case the result will be stored within the request for faster lookup.
+ * a new one will be created. In either case the result will be stored within the request for faster lookup.
*/
protected Long getConversationContextId()
{
Map requestMap;
Map requestParameterMap;
-
+
FacesContext context = FacesContext.getCurrentInstance();
if (context != null)
{
@@ -194,16 +194,16 @@
synchronized (ConversationManager.class)
{
conversationContextId = new Long(NEXT_CONVERSATION_CONTEXT);
- NEXT_CONVERSATION_CONTEXT++;
+ NEXT_CONVERSATION_CONTEXT++;
}
}
-
+
requestMap.put(CONVERSATION_CONTEXT_REQ, conversationContextId);
}
-
+
return conversationContextId;
}
-
+
/**
* Get the conversation context for the given id
*/
@@ -214,7 +214,7 @@
return (ConversationContext) conversationContexts.get(conversationContextId);
}
}
-
+
/**
* Get the conversation context for the given id. <br />
* If there is no conversation context a new one will be created
@@ -226,10 +226,10 @@
ConversationContext conversationContext = (ConversationContext) conversationContexts.get(conversationContextId);
if (conversationContext == null)
{
- conversationContext = new ConversationContext(conversationContextId.longValue());
+ conversationContext = new ConversationContext(conversationContextId.longValue());
conversationContexts.put(conversationContextId, conversationContext);
}
-
+
return conversationContext;
}
}
@@ -244,7 +244,7 @@
conversationContexts.remove(conversationContextId);
}
}
-
+
/**
* Start a conversation
* @see ConversationContext#startConversation(String, boolean)
@@ -255,10 +255,10 @@
ConversationContext conversationContext = getOrCreateConversationContext(conversationContextId);
conversationContext.startConversation(name, persistence);
}
-
+
/**
* End a conversation
- * @see ConversationContext#endConversation(String)
+ * @see ConversationContext#endConversation(String)
*/
public void endConversation(String name)
{
@@ -267,7 +267,7 @@
if (conversationContext != null)
{
conversationContext.endConversation(name);
-
+
if (!conversationContext.hasConversations())
{
destroyConversationContext(conversationContextId);
@@ -277,8 +277,8 @@
/**
* Get the conversation with the given name
- *
- * @return null if no conversation context is active or if the conversation did not exist.
+ *
+ * @return null if no conversation context is active or if the conversation did not exist.
*/
public Conversation getConversation(String name)
{
@@ -315,7 +315,7 @@
}
/**
- * Register the conversation to be ended after the cycle
+ * Register the conversation to be ended after the cycle
protected void registerEndConversation(String conversationName)
{
synchronized (registeredEndConversations)
@@ -339,7 +339,7 @@
public boolean hasConversationContext()
{
FacesContext context = FacesContext.getCurrentInstance();
-
+
return
(context.getExternalContext().getRequestMap().containsKey(CONVERSATION_CONTEXT_REQ) ||
context.getExternalContext().getRequestParameterMap().containsKey(CONVERSATION_CONTEXT_PARAM)) &&
@@ -356,7 +356,7 @@
{
return null;
}
-
+
return conversationContext.getPersistenceManager();
}
@@ -412,7 +412,7 @@
}
/**
- * Get the persistenceManagerFactory.<br />
+ * Get the persistenceManagerFactory.<br />
* The factory can be configured in your web.xml using the init parameter named
* <code>org.apache.myfaces.conversation.PERSISTENCE_MANAGER_FACTORY</code>
*/
@@ -454,7 +454,7 @@
conversationContext.attachPersistence();
}
}
-
+
protected void detachPersistence()
{
ConversationContext conversationContext = getConversationContext();
@@ -463,14 +463,23 @@
conversationContext.detachPersistence();
}
}
-
+
+ protected void purgePersistence()
+ {
+ ConversationContext conversationContext = getConversationContext();
+ if (conversationContext != null)
+ {
+ conversationContext.purgePersistence();
+ }
+ }
+
protected void checkContextTimeout()
{
synchronized (conversationContexts)
{
long timeToLive = 30 * 60 * 1000;
long checkTime = System.currentTimeMillis();
-
+
Iterator iterContexts = conversationContexts.values().iterator();
while (iterContexts.hasNext())
{
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationServletFilter.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationServletFilter.java?rev=416338&r1=416337&r2=416338&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationServletFilter.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/ConversationServletFilter.java Thu Jun 22 04:53:38 2006
@@ -15,7 +15,7 @@
{
public final static String CONVERSATION_FILTER_CALLED = "org.apache.myfaces.conversation.ConversationServletFilter.CALLED";
- private final static ThreadLocal externalContext = new ThreadLocal();
+ private final static ThreadLocal externalContext = new ThreadLocal();
public void init(FilterConfig arg0) throws ServletException
{
@@ -24,7 +24,7 @@
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
ConversationManager conversationManager = null;
-
+
if (!Boolean.TRUE.equals(request.getAttribute(CONVERSATION_FILTER_CALLED)))
{
if (request instanceof HttpServletRequest)
@@ -37,18 +37,20 @@
if (conversationManager != null)
{
externalContext.set(ConversationExternalContext.create(httpRequest));
-
+
conversationManager.attachPersistence();
}
}
}
-
+
request.setAttribute(CONVERSATION_FILTER_CALLED, Boolean.TRUE);
}
-
+
+ boolean ok = false;
try
{
chain.doFilter(request, response);
+ ok = true;
}
finally
{
@@ -56,7 +58,14 @@
{
try
{
- conversationManager.detachPersistence();
+ if (!ok)
+ {
+ conversationManager.purgePersistence();
+ }
+ else
+ {
+ conversationManager.detachPersistence();
+ }
}
finally
{
@@ -69,7 +78,7 @@
public void destroy()
{
}
-
+
protected static ConversationExternalContext getConversationExternalContext()
{
return (ConversationExternalContext) externalContext.get();
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EndConversationMethodBindingFacade.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EndConversationMethodBindingFacade.java?rev=416338&r1=416337&r2=416338&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EndConversationMethodBindingFacade.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/EndConversationMethodBindingFacade.java Thu Jun 22 04:53:38 2006
@@ -87,9 +87,11 @@
}
catch (Throwable t)
{
+ ConversationManager conversationManager = ConversationManager.getInstance(context);
+ conversationManager.purgePersistence();
+
if (errorOutcome != null)
{
- ConversationManager conversationManager = ConversationManager.getInstance(context);
conversationManager.getMessager().setConversationException(context, t);
returnValue = errorOutcome;
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManager.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManager.java?rev=416338&r1=416337&r2=416338&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManager.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/PersistenceManager.java Thu Jun 22 04:53:38 2006
@@ -16,7 +16,7 @@
package org.apache.myfaces.custom.conversation;
/**
- * the interface to help the conversation framework to deal with your persistence manager (EntityManager)
+ * the interface to help the conversation framework to deal with your persistence manager (EntityManager)
*
* @author imario@apache.org
*/
@@ -26,19 +26,24 @@
* commit the transaction
*/
public void commit();
-
+
/**
* rollback the transaction
*/
public void rollback();
-
+
/**
* attach to your underlaying persistence
*/
public void attach();
-
+
/**
* detach from your underlaying persistence
*/
public void detach();
+
+ /**
+ * purge this persistence manager - e.g. throw away your session due to some exceptions
+ */
+ void purge();
}
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIEnsureConversation.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIEnsureConversation.java?rev=416338&r1=416337&r2=416338&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIEnsureConversation.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/conversation/UIEnsureConversation.java Thu Jun 22 04:53:38 2006
@@ -17,6 +17,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.custom.redirectTracker.RedirectTrackerManager;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
@@ -89,9 +90,16 @@
String actionUrl = context.getApplication().getViewHandler().getActionURL(
context, getRedirectTo());
+ String encodedActionUrl = context.getExternalContext().encodeActionURL(actionUrl);
- context.getExternalContext().redirect(
- context.getExternalContext().encodeActionURL(actionUrl));
+ /* this is bad - but I have no clue now what to do else now ==>
+ The best will be to decorate the ExternalContext, but I see no way how to do it
+ */
+ // RedirectTrackerManager manager = RedirectTrackerManager.getInstance(context);
+ // encodedActionUrl = manager.trackRedirect(context, encodedActionUrl);
+ /* <== */
+
+ context.getExternalContext().redirect(encodedActionUrl);
return;
}