You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by md...@apache.org on 2012/08/27 16:02:57 UTC

svn commit: r1377686 - /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/ChangeProcessor.java

Author: mduerig
Date: Mon Aug 27 14:02:56 2012
New Revision: 1377686

URL: http://svn.apache.org/viewvc?rev=1377686&view=rev
Log:
OAK-279: ChangeProcessor getting stuck while shutdown
fixing the immediate issues at hand. a potential deadlock remains

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

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=1377686&r1=1377685&r2=1377686&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 Mon Aug 27 14:02:56 2012
@@ -65,19 +65,25 @@ class ChangeProcessor implements Runnabl
 
     /**
      * Stop this change processor if running. After returning from this methods no further
-     * events will be delivered. This method has no effect if the change processor is not running.
-     * A change processor is running while execution is inside its {@code run()} method.
+     * events will be delivered.
      */
     public synchronized void stop() {
-        if (running) {
-            try {
-                stopping = true;
-                future.cancel(true);
+        if (future == null) {
+            throw new IllegalStateException("Change processor not started");
+        }
+
+        try {
+            stopping = true;
+            future.cancel(true);
+            if (running) {
                 stopped.await();
             }
-            catch (InterruptedException e) {
-                Thread.currentThread().interrupt();
-            }
+        }
+        catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+        }
+        finally {
+            future = null;
         }
     }
 
@@ -96,13 +102,18 @@ class ChangeProcessor implements Runnabl
     @Override
     public void run() {
         running = true;
-        EventGeneratingNodeStateDiff diff = new EventGeneratingNodeStateDiff();
-        changeExtractor.getChanges(diff);
-        if (!stopping) {
-            diff.sendEvents();
+        try{
+            EventGeneratingNodeStateDiff diff = new EventGeneratingNodeStateDiff();
+            changeExtractor.getChanges(diff);
+            if (!stopping) {
+                diff.sendEvents();
+            }
+        } finally{
+            if (stopping) {
+                stopped.countDown();
+            }
+            running = false;
         }
-        stopped.countDown();
-        running = false;
     }
 
     //------------------------------------------------------------< private >---