CAMEL-7549 Quartz2 Endpoint with a SimpleTrigger supports referencing a bean in 
URI


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

Branch: refs/heads/master
Commit: 745aa5ce4020993e38a84c74bee0d4d9b56e89d6
Parents: a3876eb
Author: Willem Jiang <willem.ji...@gmail.com>
Authored: Fri Jun 27 16:43:09 2014 +0800
Committer: Willem Jiang <willem.ji...@gmail.com>
Committed: Fri Jun 27 16:43:54 2014 +0800

----------------------------------------------------------------------
 .../camel/component/quartz2/QuartzEndpoint.java | 10 +++--
 .../QuartzStartDelayedWithReferenceTest.java    | 46 ++++++++++++++++++++
 2 files changed, 53 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/745aa5ce/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 5f42839..6d2167d 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
@@ -30,6 +30,7 @@ import org.apache.camel.processor.loadbalancer.LoadBalancer;
 import org.apache.camel.processor.loadbalancer.RoundRobinLoadBalancer;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
+import org.apache.camel.util.EndpointHelper;
 import org.quartz.Job;
 import org.quartz.JobBuilder;
 import org.quartz.JobDataMap;
@@ -41,7 +42,6 @@ import org.quartz.TriggerBuilder;
 import org.quartz.TriggerKey;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
 import static org.quartz.CronScheduleBuilder.cronSchedule;
 import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
 
@@ -307,14 +307,18 @@ public class QuartzEndpoint extends DefaultEndpoint {
             int repeat = SimpleTrigger.REPEAT_INDEFINITELY;
             String repeatString = (String) 
triggerParameters.get("repeatCount");
             if (repeatString != null) {
-                repeat = Integer.valueOf(repeatString);
+                repeat = 
EndpointHelper.resloveStringParameter(getCamelContext(), repeatString, 
Integer.class);
+                // need to update the parameters
+                triggerParameters.put("repeatCount", repeat);
             }
 
             // default use 1 sec interval
             long interval = 1000;
             String intervalString = (String) 
triggerParameters.get("repeatInterval");
             if (intervalString != null) {
-                interval = Long.valueOf(intervalString);
+                interval = 
EndpointHelper.resloveStringParameter(getCamelContext(), intervalString, 
Long.class);
+                // need to update the parameters
+                triggerParameters.put("repeatInterval", interval);
             }
 
             TriggerBuilder<SimpleTrigger> triggerBuilder = 
TriggerBuilder.newTrigger()

http://git-wip-us.apache.org/repos/asf/camel/blob/745aa5ce/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzStartDelayedWithReferenceTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzStartDelayedWithReferenceTest.java
 
b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzStartDelayedWithReferenceTest.java
new file mode 100644
index 0000000..81887fb
--- /dev/null
+++ 
b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzStartDelayedWithReferenceTest.java
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.quartz2;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+
+public class QuartzStartDelayedWithReferenceTest extends 
QuartzStartDelayedTest {
+    
+    // just bind the reference value here
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry registry = super.createRegistry();
+        registry.bind("interval", new Long(2));
+        registry.bind("count", new Integer(1));
+        return registry;
+    }
+    
+    
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                QuartzComponent quartz = context.getComponent("quartz2", 
QuartzComponent.class);
+                quartz.setStartDelayedSeconds(2);
+
+                
from("quartz2://myGroup/myTimerName?trigger.repeatInterval=#interval&trigger.repeatCount=#count").routeId("myRoute").to("mock:result");
+            }
+        };
+    }
+
+}

Reply via email to