Author: chetanm
Date: Thu May 21 15:28:58 2015
New Revision: 1680907

URL: http://svn.apache.org/r1680907
Log:
OAK-2826 - Refactor ListeneableFutureTask to commons

Merging 1677774

Added:
    
jackrabbit/oak/branches/1.2/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/concurrent/
      - copied from r1677774, 
jackrabbit/oak/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/concurrent/
    
jackrabbit/oak/branches/1.2/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/concurrent/NotifyingFutureTaskTest.java
      - copied unchanged from r1677774, 
jackrabbit/oak/trunk/oak-commons/src/test/java/org/apache/jackrabbit/oak/commons/concurrent/NotifyingFutureTaskTest.java
Modified:
    jackrabbit/oak/branches/1.2/   (props changed)
    
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/BackgroundObserver.java

Propchange: jackrabbit/oak/branches/1.2/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu May 21 15:28:58 2015
@@ -1,3 +1,3 @@
 /jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1672350,1672468,1672537,1672603,1672642,1672644,1672834-1672835,1673351,1673410,1673414,1673436,1673644,1673662-1673664,1673669,1673695,1674046,1674065,1674075,1674107,1674228,1674880,1675054-1675055,1675332,1675354,1675357,1675382,1675555,1675566,1675593,1676198,1676237,1676407,1676458,1676539,1676670,1676693,1676703,1676725,1677579,1677581,1677609,1677611,1677939,1677991,1678173,1678323,1678758,1678938,1678954,1679144,1679165,1679191,1679235,1680182,1680222,1680232,1680236,1680461,1680805-1680806
+/jackrabbit/oak/trunk:1672350,1672468,1672537,1672603,1672642,1672644,1672834-1672835,1673351,1673410,1673414,1673436,1673644,1673662-1673664,1673669,1673695,1674046,1674065,1674075,1674107,1674228,1674880,1675054-1675055,1675332,1675354,1675357,1675382,1675555,1675566,1675593,1676198,1676237,1676407,1676458,1676539,1676670,1676693,1676703,1676725,1677579,1677581,1677609,1677611,1677774,1677939,1677991,1678173,1678323,1678758,1678938,1678954,1679144,1679165,1679191,1679235,1680182,1680222,1680232,1680236,1680461,1680805-1680806
 /jackrabbit/trunk:1345480

Modified: 
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/BackgroundObserver.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/BackgroundObserver.java?rev=1680907&r1=1680906&r2=1680907&view=diff
==============================================================================
--- 
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/BackgroundObserver.java
 (original)
+++ 
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/BackgroundObserver.java
 Thu May 21 15:28:58 2015
@@ -30,13 +30,12 @@ import java.lang.Thread.UncaughtExceptio
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.Callable;
 import java.util.concurrent.Executor;
-import java.util.concurrent.FutureTask;
-import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
 import com.google.common.base.Predicate;
+import org.apache.jackrabbit.oak.commons.concurrent.NotifyingFutureTask;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -109,7 +108,7 @@ public class BackgroundObserver implemen
     /**
      * Current background task
      */
-    private volatile ListenableFutureTask currentTask = 
ListenableFutureTask.completed();
+    private volatile NotifyingFutureTask currentTask = 
NotifyingFutureTask.completed();
 
     /**
      * Completion handler: set the current task to the next task and schedules 
that one
@@ -134,7 +133,7 @@ public class BackgroundObserver implemen
 
         @Override
         public void run() {
-            currentTask = new ListenableFutureTask(task);
+            currentTask = new NotifyingFutureTask(task);
             executor.execute(currentTask);
         }
     };
@@ -296,61 +295,4 @@ public class BackgroundObserver implemen
     private static Logger getLogger(@Nonnull Observer observer) {
         return LoggerFactory.getLogger(checkNotNull(observer).getClass());
     }
-
-    /**
-     * A future task with a on complete handler.
-     */
-    private static class ListenableFutureTask extends FutureTask<Void> {
-        private final AtomicBoolean completed = new AtomicBoolean(false);
-
-        private volatile Runnable onComplete;
-
-        public ListenableFutureTask(Callable<Void> callable) {
-            super(callable);
-        }
-
-        public ListenableFutureTask(Runnable task) {
-            super(task, null);
-        }
-
-        /**
-         * Set the on complete handler. The handler will run exactly once after
-         * the task terminated. If the task has already terminated at the time 
of
-         * this method call the handler will execute immediately.
-         * <p>
-         * Note: there is no guarantee to which handler will run when the 
method
-         * is called multiple times with different arguments.
-         * @param onComplete
-         */
-        public void onComplete(Runnable onComplete) {
-            this.onComplete = onComplete;
-            if (isDone()) {
-                run(onComplete);
-            }
-        }
-
-        @Override
-        protected void done() {
-            run(onComplete);
-        }
-
-        private void run(Runnable onComplete) {
-            if (onComplete != null && completed.compareAndSet(false, true)) {
-                onComplete.run();
-            }
-        }
-
-        private static final Runnable NOP = new Runnable() {
-            @Override
-            public void run() {
-            }
-        };
-
-        public static ListenableFutureTask completed() {
-            ListenableFutureTask f = new ListenableFutureTask(NOP);
-            f.run();
-            return f;
-        }
-    }
-
 }


Reply via email to