camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/3] git commit: CAMEL-7308: Timer consumer should defer schedluing during Camel startup to after when Camel has started using the startup listener, like other component does like quartz etc. Thanks to Metatech for the patch.
Date Thu, 20 Mar 2014 10:07:19 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.12.x 8a5fe8e99 -> e7975d77d
  refs/heads/camel-2.13.x aca020e61 -> ec8ae31e5
  refs/heads/master baeddbc1b -> 080b5f27e


CAMEL-7308: Timer consumer should defer schedluing during Camel startup to after when Camel
has started using the startup listener, like other component does like quartz etc. Thanks
to Metatech for the patch.


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

Branch: refs/heads/master
Commit: 080b5f27ed9fffcc667dbf3300eea1c232f004cf
Parents: baeddbc
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Mar 20 11:09:03 2014 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Mar 20 11:09:03 2014 +0100

----------------------------------------------------------------------
 .../camel/component/timer/TimerConsumer.java    | 24 +++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/080b5f27/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java
b/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java
index d6f7254..66617d2 100644
--- a/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java
+++ b/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java
@@ -22,8 +22,10 @@ import java.util.TimerTask;
 import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.camel.AsyncCallback;
+import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
+import org.apache.camel.StartupListener;
 import org.apache.camel.impl.DefaultConsumer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -33,10 +35,11 @@ import org.slf4j.LoggerFactory;
  *
  * @version 
  */
-public class TimerConsumer extends DefaultConsumer {
+public class TimerConsumer extends DefaultConsumer implements StartupListener {
     private static final Logger LOG = LoggerFactory.getLogger(TimerConsumer.class);
     private final TimerEndpoint endpoint;
     private volatile TimerTask task;
+    private volatile boolean configured;
 
     public TimerConsumer(TimerEndpoint endpoint, Processor processor) {
         super(endpoint, processor);
@@ -53,6 +56,7 @@ public class TimerConsumer extends DefaultConsumer {
             public void run() {
                 if (!isTaskRunAllowed()) {
                     // do not run timer task as it was not allowed
+                    LOG.debug("Run now allowed for timer: {}", endpoint);
                     return;
                 }
 
@@ -74,8 +78,12 @@ public class TimerConsumer extends DefaultConsumer {
             }
         };
 
-        Timer timer = endpoint.getTimer();
-        configureTask(task, timer);
+        // only configure task if CamelContext already started, otherwise the StartupListener
+        // is configuring the task later
+        if (!configured && endpoint.getCamelContext().getStatus().isStarted()) {
+            Timer timer = endpoint.getTimer();
+            configureTask(task, timer);
+        }
     }
 
     @Override
@@ -84,6 +92,15 @@ public class TimerConsumer extends DefaultConsumer {
             task.cancel();
         }
         task = null;
+        configured = false;
+    }
+
+    @Override
+    public void onCamelContextStarted(CamelContext context, boolean alreadyStarted) throws
Exception {
+        if (task != null && !configured) {
+            Timer timer = endpoint.getTimer();
+            configureTask(task, timer);
+        }
     }
 
     /**
@@ -117,6 +134,7 @@ public class TimerConsumer extends DefaultConsumer {
                 }
             }
         }
+        configured = true;
     }
 
     protected void sendTimerExchange(long counter) {


Mime
View raw message