You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sk...@apache.org on 2008/07/08 17:23:47 UTC
svn commit: r674857 -
/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationContext.java
Author: skitching
Date: Tue Jul 8 08:23:46 2008
New Revision: 674857
URL: http://svn.apache.org/viewvc?rev=674857&view=rev
Log:
Have a ConversationContext keep track of its child contexts directly. In
particular, we need to know whether a context has children in order to
know whether to apply timeout checks or not; contexts with children
should never time out.
Modified:
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationContext.java
Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationContext.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationContext.java?rev=674857&r1=674856&r2=674857&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationContext.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationContext.java Tue Jul 8 08:23:46 2008
@@ -21,9 +21,11 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.orchestra.lib.OrchestraException;
import org.apache.myfaces.orchestra.lib._ReentrantLock;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
@@ -74,6 +76,9 @@
private final _ReentrantLock lock = new _ReentrantLock();
+ // Map of all child contexts of this context, keyed by child.id
+ private Map childContexts = new HashMap();
+
/**
* Constructor.
*/
@@ -92,6 +97,11 @@
this.parent = parent;
this.id = Long.valueOf(id);
+ if (parent != null)
+ {
+ parent.addChild(this);
+ }
+
touch();
}
@@ -142,6 +152,36 @@
}
/**
+ * @since 1.3
+ */
+ public void addChild(ConversationContext context)
+ {
+ childContexts.put(context.getIdAsLong(), context);
+ }
+
+ /**
+ * @since 1.3
+ */
+ public void removeChild(ConversationContext context)
+ {
+ Object o = childContexts.remove(context.getIdAsLong());
+ if (o != context)
+ {
+ // Sanity check failed: o is null, or o is a different object.
+ // In either case, something is very wrong.
+ throw new OrchestraException("Invalid call of removeChild");
+ }
+ }
+
+ /**
+ * @since 1.3
+ */
+ public boolean hasChildren()
+ {
+ return !childContexts.isEmpty();
+ }
+
+ /**
* Mark this context as having been used.
*/
protected void touch()
@@ -184,9 +224,21 @@
/**
* Invalidate all conversations within this context.
+ *
+ * @deprecated Use the "invalidate" method instead.
*/
protected void clear()
{
+ invalidate();
+ }
+
+ /**
+ * Invalidate all conversations within this context.
+ *
+ * @since 1.3
+ */
+ protected void invalidate()
+ {
synchronized (this)
{
Conversation[] convArray = new Conversation[conversations.size()];
@@ -254,7 +306,7 @@
}
/**
- * See if there is a conversation with the specified name.
+ * Return true if there are one or more conversations in this context.
*/
protected boolean hasConversations()
{
@@ -279,6 +331,10 @@
/**
* Get a conversation by name.
+ * <p>
+ * This looks only in the current context.
+ *
+ * @since 1.3
*/
protected Conversation getConversation(String name)
{
@@ -298,6 +354,8 @@
/**
* Iterates over all the conversations in this context.
+ * <p>
+ * This does not include conversations in parent contexts.
*
* @return An iterator over a copy of the conversation list. It is safe to remove objects from
* the conversation list while iterating, as the iterator refers to a different collection.