jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r999406 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: SessionImpl.java observation/ObservationDispatcher.java session/SessionContext.java session/SessionState.java
Date Tue, 21 Sep 2010 13:31:52 GMT
Author: thomasm
Date: Tue Sep 21 13:31:51 2010
New Revision: 999406

URL: http://svn.apache.org/viewvc?rev=999406&view=rev
Log:
JCR-2746 Sleep in possibly endless loop in ObservationDispatcher

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/ObservationDispatcher.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionContext.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java?rev=999406&r1=999405&r2=999406&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
Tue Sep 21 13:31:51 2010
@@ -1238,4 +1238,15 @@ public class SessionImpl extends Abstrac
             logout();
         }
     }
+
+    /**
+     * Delay the next operation, except if it is run using the given thread.
+     *
+     * @param exceptInThread the thread that shouldn't be delayed
+     * @param ms the delay in milliseconds
+     */
+    public void delayNextOperation(Thread exceptInThread, long ms) {
+        context.delayNextOperation(exceptInThread, ms);
+    }
+
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/ObservationDispatcher.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/ObservationDispatcher.java?rev=999406&r1=999405&r2=999406&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/ObservationDispatcher.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/ObservationDispatcher.java
Tue Sep 21 13:31:51 2010
@@ -236,12 +236,11 @@ public final class ObservationDispatcher
                 if (logWarning) {
                     log.warn("Waiting");
                 }
-                while (eventQueueSize.get() > MAX_QUEUED_EVENTS) {
-                    try {
-                        Thread.sleep(100);
-                    } catch (InterruptedException e) {
-                        // ignore
-                    }
+                if (eventQueueSize.get() > MAX_QUEUED_EVENTS) {
+                    // slow down the current session
+                    // but not here, because locks are held
+                    // (that may block an observation listener, which is not what we want)
+                    events.getSession().delayNextOperation(notificationThread, 100);
                 }
             }
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionContext.java?rev=999406&r1=999405&r2=999406&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionContext.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionContext.java
Tue Sep 21 13:31:51 2010
@@ -58,6 +58,19 @@ public class SessionContext implements N
     private static AtomicLong counter = new AtomicLong();
 
     /**
+     * The thread in which not to delay operations.
+     * If null, no operations are delayed.
+     * If not null, the next operation is delayed,
+     * except operations that are executed from this thread.
+     */
+    private Thread delayExceptInThread;
+
+    /**
+     * The delay in milliseconds.
+     */
+    private long delayMs;
+
+    /**
      * Creates a unique internal session name for a session with the
      * given user.
      *
@@ -361,4 +374,33 @@ public class SessionContext implements N
         return sessionName;
     }
 
+    /**
+     * Delay the next operation, except if it is run using the given thread.
+     *
+     * @param exceptInThread the thread that shouldn't be delayed
+     * @param ms the delay in milliseconds
+     */
+    public void delayNextOperation(Thread exceptInThread, long ms) {
+        this.delayExceptInThread = exceptInThread;
+        this.delayMs = ms;
+    }
+
+    /**
+     * Delay a session operation if it is necessary.
+     */
+    public void delayIfNecessary() {
+        if (delayExceptInThread != null) {
+            Thread currentThread = Thread.currentThread();
+            if (currentThread != delayExceptInThread) {
+                try {
+                    Thread.sleep(delayMs);
+                } catch (InterruptedException e) {
+                    // ignore
+                }
+                // don't delay the next operation
+                delayExceptInThread = null;
+            }
+        }
+    }
+
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java?rev=999406&r1=999405&r2=999406&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java
Tue Sep 21 13:31:51 2010
@@ -190,6 +190,7 @@ public class SessionState {
                         }
                     }
                 } else {
+                    context.delayIfNecessary();
                     return operation.perform(context);
                 }
             } finally {



Mime
View raw message