camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] git commit: CAMEL-7103: camel-quarz2 now stores trigger information in job data map, so end users have that information in Camel message routes.
Date Fri, 03 Jan 2014 12:26:20 GMT
Updated Branches:
  refs/heads/camel-2.12.x a4c2dcea1 -> 3b1f28569
  refs/heads/master ccc92124f -> c6b8166f9


CAMEL-7103: camel-quarz2 now stores trigger information in job data map, so end users have
that information in Camel message routes.


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

Branch: refs/heads/master
Commit: c6b8166f935f3a5334e0d40267c99bb5fdc64918
Parents: ccc9212
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Fri Jan 3 13:29:17 2014 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Jan 3 13:29:17 2014 +0100

----------------------------------------------------------------------
 .../camel/component/quartz2/QuartzConstants.java      |  6 ++++++
 .../camel/component/quartz2/QuartzEndpoint.java       | 14 ++++++++++++--
 .../quartz2/QuartzScheduledPollConsumerScheduler.java |  5 +++++
 .../camel/component/quartz2/QuartzCronRouteTest.java  |  3 +++
 .../component/quartz2/QuartzSimpleRouteTest.java      |  4 ++++
 5 files changed, 30 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/c6b8166f/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzConstants.java
b/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzConstants.java
index 07284ce..3386a71 100644
--- a/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzConstants.java
+++ b/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzConstants.java
@@ -29,6 +29,12 @@ public final class QuartzConstants {
 
     public static final String QUARTZ_CAMEL_CONTEXT = "CamelQuartzCamelContext";
 
+    public static final String QUARTZ_TRIGGER_TYPE = "CamelQuartzTriggerType";
+    public static final String QUARTZ_TRIGGER_CRON_EXPRESSION = "CamelQuartzTriggerCronExpression";
+    public static final String QUARTZ_TRIGGER_CRON_TIMEZONE = "CamelQuartzTriggerCronTimeZone";
+    public static final String QUARTZ_TRIGGER_SIMPLE_REPEAT_COUNTER = "CamelQuartzTriggerSimpleRepeatCounter";
+    public static final String QUARTZ_TRIGGER_SIMPLE_REPEAT_INTERVAL = "CamelQuartzTriggerSimpleRepeatInterval";
+
     private QuartzConstants() {
         // Utility class
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/c6b8166f/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java
b/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java
index de94beb..2ea291a 100644
--- a/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java
+++ b/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java
@@ -215,7 +215,7 @@ public class QuartzEndpoint extends DefaultEndpoint {
         Trigger trigger = scheduler.getTrigger(triggerKey);
         if (trigger == null) {
             jobDetail = createJobDetail();
-            trigger = createTrigger();
+            trigger = createTrigger(jobDetail);
 
             updateJobDataMap(jobDetail);
 
@@ -261,7 +261,7 @@ public class QuartzEndpoint extends DefaultEndpoint {
         jobDataMap.put(QuartzConstants.QUARTZ_ENDPOINT_URI, endpointUri);
     }
 
-    private Trigger createTrigger() throws Exception {
+    private Trigger createTrigger(JobDetail jobDetail) throws Exception {
         Trigger result;
         Date startTime = new Date();
         if (getComponent().getScheduler().isStarted()) {
@@ -274,6 +274,11 @@ public class QuartzEndpoint extends DefaultEndpoint {
                     .startAt(startTime)
                     .withSchedule(cronSchedule(cron).withMisfireHandlingInstructionFireAndProceed())
                     .build();
+
+            // enrich job map with details
+            jobDetail.getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_TYPE, "cron");
+            jobDetail.getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_CRON_EXPRESSION,
cron);
+
         } else {
             LOG.debug("Creating SimpleTrigger.");
             int repeat = SimpleTrigger.REPEAT_INDEFINITELY;
@@ -300,6 +305,11 @@ public class QuartzEndpoint extends DefaultEndpoint {
             }
 
             result = triggerBuilder.build();
+
+            // enrich job map with details
+            jobDetail.getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_TYPE, "simple");
+            jobDetail.getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_SIMPLE_REPEAT_COUNTER,
repeat);
+            jobDetail.getJobDataMap().put(QuartzConstants.QUARTZ_TRIGGER_SIMPLE_REPEAT_INTERVAL,
interval);
         }
 
         if (triggerParameters != null && triggerParameters.size() > 0) {

http://git-wip-us.apache.org/repos/asf/camel/blob/c6b8166f/components/camel-quartz2/src/main/java/org/apache/camel/pollconsumer/quartz2/QuartzScheduledPollConsumerScheduler.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/main/java/org/apache/camel/pollconsumer/quartz2/QuartzScheduledPollConsumerScheduler.java
b/components/camel-quartz2/src/main/java/org/apache/camel/pollconsumer/quartz2/QuartzScheduledPollConsumerScheduler.java
index 14787a8..0e65438 100644
--- a/components/camel-quartz2/src/main/java/org/apache/camel/pollconsumer/quartz2/QuartzScheduledPollConsumerScheduler.java
+++ b/components/camel-quartz2/src/main/java/org/apache/camel/pollconsumer/quartz2/QuartzScheduledPollConsumerScheduler.java
@@ -21,6 +21,7 @@ import java.util.TimeZone;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Consumer;
 import org.apache.camel.component.quartz2.QuartzComponent;
+import org.apache.camel.component.quartz2.QuartzConstants;
 import org.apache.camel.spi.ScheduledPollConsumerScheduler;
 import org.apache.camel.support.ServiceSupport;
 import org.apache.camel.util.ObjectHelper;
@@ -151,6 +152,10 @@ public class QuartzScheduledPollConsumerScheduler extends ServiceSupport
impleme
 
         JobDataMap map = new JobDataMap();
         map.put("task", runnable);
+        map.put(QuartzConstants.QUARTZ_TRIGGER_TYPE, "cron");
+        map.put(QuartzConstants.QUARTZ_TRIGGER_CRON_EXPRESSION, getCron());
+        map.put(QuartzConstants.QUARTZ_TRIGGER_CRON_TIMEZONE, getTimeZone().getID());
+
         job = JobBuilder.newJob(QuartzScheduledPollConsumerJob.class)
                 .usingJobData(map)
                 .build();

http://git-wip-us.apache.org/repos/asf/camel/blob/c6b8166f/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzCronRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzCronRouteTest.java
b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzCronRouteTest.java
index 34b7c85..0c4e94b 100644
--- a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzCronRouteTest.java
+++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzCronRouteTest.java
@@ -43,6 +43,9 @@ public class QuartzCronRouteTest extends BaseQuartzTest {
 
         JobDetail detail = mock.getReceivedExchanges().get(0).getIn().getHeader("jobDetail",
JobDetail.class);
         Assert.assertThat(detail.getJobClass().equals(CamelJob.class), CoreMatchers.is(true));
+
+        Assert.assertThat(detail.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_TYPE).equals("cron"),
CoreMatchers.is(true));
+        Assert.assertThat(detail.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_CRON_EXPRESSION).equals("0/2
* * * * ?"), CoreMatchers.is(true));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/c6b8166f/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzSimpleRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzSimpleRouteTest.java
b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzSimpleRouteTest.java
index adb1113..abc7d3c 100644
--- a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzSimpleRouteTest.java
+++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzSimpleRouteTest.java
@@ -42,6 +42,10 @@ public class QuartzSimpleRouteTest extends BaseQuartzTest {
 
         JobDetail detail = mock.getReceivedExchanges().get(0).getIn().getHeader("jobDetail",
JobDetail.class);
         Assert.assertThat(detail.getJobClass().equals(CamelJob.class), CoreMatchers.is(true));
+
+        Assert.assertThat(detail.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_TYPE).equals("simple"),
CoreMatchers.is(true));
+        Assert.assertThat(detail.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_SIMPLE_REPEAT_COUNTER).equals(-1),
CoreMatchers.is(true));
+        Assert.assertThat(detail.getJobDataMap().get(QuartzConstants.QUARTZ_TRIGGER_SIMPLE_REPEAT_INTERVAL).equals(2000L),
CoreMatchers.is(true));
     }
 
     @Override


Mime
View raw message