You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/03/09 09:02:34 UTC
[2/2] git commit: CAMEL-7280: camel-quartz2 - add options to uri to
set job as durable/recoverable.
CAMEL-7280: camel-quartz2 - add options to uri to set job as durable/recoverable.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b140b6bc
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b140b6bc
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b140b6bc
Branch: refs/heads/camel-2.12.x
Commit: b140b6bc54c7448ab6d88bf7627077d4f3b46173
Parents: daf7415
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Mar 9 09:04:14 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Mar 9 09:04:38 2014 +0100
----------------------------------------------------------------------
.../camel/component/quartz2/QuartzEndpoint.java | 34 +++++++++++++++---
.../quartz2/QuartzCronRouteDurableJobTest.java | 36 ++++++++++++++++++++
2 files changed, 66 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/b140b6bc/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 fbc5738..94a2077 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
@@ -59,6 +59,8 @@ public class QuartzEndpoint extends DefaultEndpoint {
private boolean fireNow;
private boolean deleteJob = true;
private boolean pauseJob;
+ private boolean durableJob;
+ private boolean recoverableJob;
/** In case of scheduler has already started, we want the trigger start slightly after current time to
* ensure endpoint is fully started before the job kicks in. */
private long triggerStartDelay = 500; // in millis second
@@ -115,6 +117,22 @@ public class QuartzEndpoint extends DefaultEndpoint {
this.stateful = stateful;
}
+ public boolean isDurableJob() {
+ return durableJob;
+ }
+
+ public void setDurableJob(boolean durableJob) {
+ this.durableJob = durableJob;
+ }
+
+ public boolean isRecoverableJob() {
+ return recoverableJob;
+ }
+
+ public void setRecoverableJob(boolean recoverableJob) {
+ this.recoverableJob = recoverableJob;
+ }
+
public void setTriggerParameters(Map<String, Object> triggerParameters) {
this.triggerParameters = triggerParameters;
}
@@ -301,7 +319,7 @@ public class QuartzEndpoint extends DefaultEndpoint {
.withRepeatCount(repeat).withIntervalInMilliseconds(interval));
if (fireNow) {
- triggerBuilder.startNow();
+ triggerBuilder = triggerBuilder.startNow();
}
result = triggerBuilder.build();
@@ -328,9 +346,17 @@ public class QuartzEndpoint extends DefaultEndpoint {
Class<? extends Job> jobClass = stateful ? StatefulCamelJob.class : CamelJob.class;
LOG.debug("Creating new {}.", jobClass.getSimpleName());
- JobDetail result = JobBuilder.newJob(jobClass)
- .withIdentity(name, group)
- .build();
+ JobBuilder builder = JobBuilder.newJob(jobClass)
+ .withIdentity(name, group);
+
+ if (durableJob) {
+ builder = builder.storeDurably();
+ }
+ if (recoverableJob) {
+ builder = builder.requestRecovery();
+ }
+
+ JobDetail result = builder.build();
// Let user parameters to further set JobDetail properties.
if (jobParameters != null && jobParameters.size() > 0) {
http://git-wip-us.apache.org/repos/asf/camel/blob/b140b6bc/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzCronRouteDurableJobTest.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzCronRouteDurableJobTest.java b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzCronRouteDurableJobTest.java
new file mode 100644
index 0000000..f86824f
--- /dev/null
+++ b/components/camel-quartz2/src/test/java/org/apache/camel/component/quartz2/QuartzCronRouteDurableJobTest.java
@@ -0,0 +1,36 @@
+/**
+ * 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;
+
+/**
+ * This test the CronTrigger as a timer endpoint in a route.
+ */
+public class QuartzCronRouteDurableJobTest extends QuartzCronRouteTest {
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ // triggers every 2th second at precise 00,02,04,06..58
+ // notice we must use + as space when configured using URI parameter
+ from("quartz2://myGroup/myTimerName?durableJob=true&recoverableJob=true&cron=0/2+*+*+*+*+?").to("mock:result");
+ }
+ };
+ }
+}
\ No newline at end of file