Author: mduerig
Date: Tue Mar 18 13:34:47 2014
New Revision: 1578872

URL: http://svn.apache.org/r1578872
Log:
OAK-1532: ShareableNodesTest.testAddShareableMixin failures
Make ChangeProcessor.stop() idempotent instead of throwing an 
IllegalStateException

Modified:
    jackrabbit/oak/trunk/oak-jcr/pom.xml
    
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java

Modified: jackrabbit/oak/trunk/oak-jcr/pom.xml
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/pom.xml?rev=1578872&r1=1578871&r2=1578872&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-jcr/pom.xml Tue Mar 18 13:34:47 2014
@@ -144,9 +144,6 @@
       org.apache.jackrabbit.core.query.ShareableNodeTest#testName              
                      <!-- OAK-118 -->
       org.apache.jackrabbit.core.query.ShareableNodeTest#testPathConstraint    
                      <!-- OAK-118 -->
       org.apache.jackrabbit.oak.jcr.query.QueryTest#fnNameEncoding             
                      <!-- OAK-1000 -->
-
-      
org.apache.jackrabbit.core.observation.ShareableNodesTest#testAddShareableMixin 
<!-- OAK-1532 -->
-
     </known.issues>
   </properties>
 

Modified: 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java?rev=1578872&r1=1578871&r2=1578872&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java
 Tue Mar 18 13:34:47 2014
@@ -174,23 +174,30 @@ class ChangeProcessor implements Observe
      * the specified time for a pending event listener to complete. If
      * no timeout occurred no further events will be delivered after this
      * method returns.
+     * <p>
+     * Does nothing if stopped already.
      *
      * @param timeOut time this method will wait for an executing event
      *                listener to complete.
      * @param unit    time unit for {@code timeOut}
      * @return {@code true} if no time out occurred and this change processor
      *         could be stopped, {@code false} otherwise.
-     * @throws IllegalStateException if not yet started or stopped already
+     * @throws IllegalStateException if not yet started
      */
     public synchronized boolean stopAndWait(int timeOut, TimeUnit unit) {
         checkState(registration != null, "Change processor not started");
-        running.stop();
-        if (runningMonitor.enter(timeOut, unit)) {
-            registration.unregister();
-            runningMonitor.leave();
-            return true;
+        if (running.stop()) {
+            if (runningMonitor.enter(timeOut, unit)) {
+                registration.unregister();
+                runningMonitor.leave();
+                return true;
+            } else {
+                // Timed out
+                return false;
+            }
         } else {
-            return false;
+            // Stopped already
+            return true;
         }
     }
 
@@ -202,9 +209,10 @@ class ChangeProcessor implements Observe
      */
     public synchronized void stop() {
         checkState(registration != null, "Change processor not started");
-        running.stop();
-        registration.unregister();
-        runningMonitor.leave();
+        if (running.stop()) {
+            registration.unregister();
+            runningMonitor.leave();
+        }
     }
 
     @Override
@@ -274,9 +282,14 @@ class ChangeProcessor implements Observe
             return !stopped;
         }
 
-        public void stop() {
-            checkState(!stopped, "Change processor already stopped");
+        /**
+         * @return  {@code true} if this call set this guard to stopped,
+         *          {@code false} if another call set this guard to stopped 
before.
+         */
+        public boolean stop() {
+            boolean wasStopped = stopped;
             stopped = true;
+            return !wasStopped;
         }
     }
 }


Reply via email to