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/02/07 17:19:09 UTC
svn commit: r619480 -
/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/conversation/ConversationContext.java
Author: skitching
Date: Thu Feb 7 08:19:06 2008
New Revision: 619480
URL: http://svn.apache.org/viewvc?rev=619480&view=rev
Log:
Add facility for conversation contexts to be locked by thread.
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=619480&r1=619479&r2=619480&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 Thu Feb 7 08:19:06 2008
@@ -19,14 +19,15 @@
package org.apache.myfaces.orchestra.conversation;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
import java.util.Arrays;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.orchestra.lib._ReentrantLock;
+
/**
* A ConversationContext is a container for a set of conversations.
* <p>
@@ -57,6 +58,8 @@
// default timeout for contexts: 30 minutes.
private long timeoutMillis = 30 * 60 * 1000;
+
+ private final _ReentrantLock lock = new _ReentrantLock();
protected ConversationContext(long id)
{
@@ -319,5 +322,37 @@
{
return attributes.remove(name);
}
+ }
+
+ /**
+ * Block until no other thread has this instance marked as reserved, then
+ * mark the object as reserved for this thread.
+ * <p>
+ * It is safe to call this method multiple times.
+ * <p>
+ * If this method is called, then an equal number of calls to
+ * unlockForCurrentThread <b>MUST</b> made, or this context object
+ * will remain locked until the http session times out.
+ */
+ public void lockInterruptablyForCurrentThread() throws InterruptedException
+ {
+ lock.lockInterruptibly();
+ }
+
+ /**
+ * Block until no other thread has this instance marked as reserved, then
+ * mark the object as reserved for this thread.
+ */
+ public void unlockForCurrentThread()
+ {
+ lock.unlock();
+ }
+
+ /**
+ * Return true if this object is currently locked by the calling thread.
+ */
+ public boolean isLockedForCurrentThread()
+ {
+ return lock.isHeldByCurrentThread();
}
}