camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r540976 - in /activemq/camel/trunk/components/camel-quartz/src: main/java/org/apache/camel/component/quartz/QuartzComponent.java test/java/org/apache/camel/component/quartz/QuartzEndpointConfigureTest.java
Date Wed, 23 May 2007 15:38:22 GMT
Author: jstrachan
Date: Wed May 23 08:38:21 2007
New Revision: 540976

URL: http://svn.apache.org/viewvc?view=rev&rev=540976
Log:
added support for cron expressions in URIs

Modified:
    activemq/camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
    activemq/camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzEndpointConfigureTest.java

Modified: activemq/camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java?view=diff&rev=540976&r1=540975&r2=540976
==============================================================================
--- activemq/camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
(original)
+++ activemq/camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
Wed May 23 08:38:21 2007
@@ -28,6 +28,7 @@
 import org.quartz.SchedulerException;
 import org.quartz.SchedulerFactory;
 import org.quartz.Trigger;
+import org.quartz.CronTrigger;
 import org.quartz.impl.StdSchedulerFactory;
 
 import java.util.Map;
@@ -55,16 +56,33 @@
 
     @Override
     protected QuartzEndpoint createEndpoint(String uri, String remaining, Map parameters)
throws Exception {
+        QuartzEndpoint answer = new QuartzEndpoint(uri, this, getScheduler());
+
         // lets split the remaining into a group/name
         URI u = new URI(uri);
         String name;
         String group = "Camel";
         String path = u.getPath();
+        CronTrigger cronTrigger = null;
         if (path != null && path.length() > 1) {
             if (path.startsWith("/")) {
                 path = path.substring(1);
             }
-            name = path;
+            int idx = path.indexOf('/');
+            if (idx > 0) {
+                cronTrigger = new CronTrigger();
+                name = path.substring(0, idx);
+                String cronExpression = path.substring(idx + 1);
+                // lets allow / instead of spaces and allow $ instead of ?
+                cronExpression = cronExpression.replace('/', ' ');
+                cronExpression = cronExpression.replace('$', '?');
+                log.debug("Creating cron trigger: " + cronExpression);
+                cronTrigger.setCronExpression(cronExpression);
+                answer.setTrigger(cronTrigger);
+            }
+            else {
+                name = path;
+            }
             group = u.getHost();
         }
         else {
@@ -80,8 +98,10 @@
             name = names[0];
         }
 */
-        QuartzEndpoint answer = new QuartzEndpoint(uri, this, getScheduler());
-        Trigger trigger = answer.getTrigger();
+        Trigger trigger = cronTrigger;
+        if (trigger == null) {
+            trigger = answer.getTrigger();
+        }
         trigger.setName(name);
         trigger.setGroup(group);
 

Modified: activemq/camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzEndpointConfigureTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzEndpointConfigureTest.java?view=diff&rev=540976&r1=540975&r2=540976
==============================================================================
--- activemq/camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzEndpointConfigureTest.java
(original)
+++ activemq/camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzEndpointConfigureTest.java
Wed May 23 08:38:21 2007
@@ -21,6 +21,7 @@
 import org.apache.camel.Endpoint;
 import org.quartz.Trigger;
 import org.quartz.SimpleTrigger;
+import org.quartz.CronTrigger;
 
 /**
  * @version $Revision: 1.1 $
@@ -42,6 +43,14 @@
         Trigger trigger = endpoint.getTrigger();
         assertEquals("getName()", "myName", trigger.getName());
         assertEquals("getGroup()", "Camel", trigger.getGroup());
+    }
+
+    public void testConfigureCronExpression() throws Exception {
+        QuartzEndpoint endpoint = resolveMandatoryEndpoint("quartz://myGroup/myTimerName/0/0/12/*/*/$");
+        CronTrigger trigger = assertIsInstanceOf(CronTrigger.class, endpoint.getTrigger());
+        assertEquals("getName()", "myTimerName", trigger.getName());
+        assertEquals("getGroup()", "myGroup", trigger.getGroup());
+        assertEquals("cron expression", "0 0 12 * * ?", trigger.getCronExpression());
     }
 
     @Override



Mime
View raw message