Author: ningjiang
Date: Wed Dec 30 07:01:04 2009
New Revision: 894550
URL: http://svn.apache.org/viewvc?rev=894550&view=rev
Log:
CAMEL-2324 Implemented fireNow option on camel-quartz component
Added:
camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzRouteFireNowTest.java
(with props)
Modified:
camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
Modified:
camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java?rev=894550&r1=894549&r2=894550&view=diff
==============================================================================
---
camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
(original)
+++
camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
Wed Dec 30 07:01:04 2009
@@ -18,6 +18,7 @@
import java.net.URI;
import java.text.ParseException;
+import java.util.Date;
import java.util.Map;
import org.apache.camel.CamelContext;
@@ -63,6 +64,7 @@
String path = ObjectHelper.after(u.getPath(), "/");
String host = u.getHost();
String cron = getAndRemoveParameter(parameters, "cron", String.class);
+ Boolean fireNow = getAndRemoveParameter(parameters, "fireNow",
Boolean.class, Boolean.FALSE);
// group can be optional, if so set it to Camel
String name;
@@ -75,21 +77,28 @@
name = host;
}
+ Map<String, Object> triggerParameters =
IntrospectionSupport.extractProperties(parameters, "trigger.");
+ Map<String, Object> jobParameters =
IntrospectionSupport.extractProperties(parameters, "job.");
+
// create the trigger either cron or simple
Trigger trigger;
if (ObjectHelper.isNotEmpty(cron)) {
trigger = createCronTrigger(cron);
} else {
trigger = new SimpleTrigger();
+ if (fireNow) {
+ String intervalString = (String)
triggerParameters.get("repeatInterval");
+ if (intervalString != null) {
+ long interval = Long.valueOf(intervalString);
+ trigger.setStartTime(new Date(System.currentTimeMillis() -
interval));
+ }
+ }
}
answer.setTrigger(trigger);
trigger.setName(name);
trigger.setGroup(group);
-
- Map<String, Object> triggerParameters =
IntrospectionSupport.extractProperties(parameters, "trigger.");
- Map<String, Object> jobParameters =
IntrospectionSupport.extractProperties(parameters, "job.");
-
+
setProperties(trigger, triggerParameters);
setProperties(answer.getJobDetail(), jobParameters);
Added:
camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzRouteFireNowTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzRouteFireNowTest.java?rev=894550&view=auto
==============================================================================
---
camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzRouteFireNowTest.java
(added)
+++
camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzRouteFireNowTest.java
Wed Dec 30 07:01:04 2009
@@ -0,0 +1,44 @@
+/**
+ * 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.quartz;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class QuartzRouteFireNowTest extends QuartzRouteTest {
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ // START SNIPPET: example
+
from("quartz://myGroup/myTimerName?fireNow=true&trigger.repeatInterval=25000&trigger.repeatCount=2").to("mock:result");
+ // END SNIPPET: example
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange:
camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzRouteFireNowTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzRouteFireNowTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date