Repository: camel
Updated Branches:
  refs/heads/master dd0ed95d5 -> 100ce2487


CAMEL-9826: used CountDownLatch to wait for stop


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1552d093
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1552d093
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1552d093

Branch: refs/heads/master
Commit: 1552d093786156ccb43eb488a120fb854021f986
Parents: dd0ed95
Author: Arno Noordover <anoordo...@users.noreply.github.com>
Authored: Sun May 29 12:47:05 2016 +0200
Committer: Arno Noordover <anoordo...@users.noreply.github.com>
Committed: Sun May 29 12:47:05 2016 +0200

----------------------------------------------------------------------
 .../component/mongodb/MongoDbTailingProcess.java      | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1552d093/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbTailingProcess.java
----------------------------------------------------------------------
diff --git 
a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbTailingProcess.java
 
b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbTailingProcess.java
index 2eaf6e1..ed11b6d 100644
--- 
a/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbTailingProcess.java
+++ 
b/components/camel-mongodb/src/main/java/org/apache/camel/component/mongodb/MongoDbTailingProcess.java
@@ -39,6 +39,7 @@ public class MongoDbTailingProcess implements Runnable {
 
     public volatile boolean keepRunning = true;
     public volatile boolean stopped; // = false
+    private volatile CountDownLatch stoppedLatch;
 
     private final DBCollection dbCol;
     private final MongoDbEndpoint endpoint;
@@ -98,6 +99,7 @@ public class MongoDbTailingProcess implements Runnable {
      */
     @Override
     public void run() {
+        stoppedLatch = new CountDownLatch(1);
         while (keepRunning) {
             doRun();
             // if the previous call didn't return because we have stopped 
running, then regenerate the cursor
@@ -120,6 +122,7 @@ public class MongoDbTailingProcess implements Runnable {
         }
 
         stopped = true;
+        stoppedLatch.countDown();
     }
 
     protected void stop() throws Exception {
@@ -131,8 +134,7 @@ public class MongoDbTailingProcess implements Runnable {
         if (cursor != null) {
             cursor.close();
         }
-        // wait until the main loop acknowledges the stop
-        while (!stopped) { }
+        awaitStopped();
         if (LOG.isInfoEnabled()) {
             LOG.info("Stopped MongoDB Tailable Cursor consumer, bound to 
collection: {}", "db: " + dbCol.getDB() + ", col: " + dbCol.getName());
         }
@@ -183,4 +185,12 @@ public class MongoDbTailingProcess implements Runnable {
         }
         return answer;
     }
+
+    private void awaitStopped() throws InterruptedException {
+        if (!stopped) {
+            LOG.info("Going to wait for stopping");
+            stoppedLatch.await();
+        }
+    }
+
 }

Reply via email to