Repository: camel Updated Branches: refs/heads/camel-2.12.x daf741545 -> b140b6bc5 refs/heads/master ecdbad6cc -> 9b9e17d80
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/9b9e17d8 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9b9e17d8 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9b9e17d8 Branch: refs/heads/master Commit: 9b9e17d801d29f860381294f43f362f11b95d8c9 Parents: ecdbad6 Author: Claus Ibsen <[email protected]> Authored: Sun Mar 9 09:04:14 2014 +0100 Committer: Claus Ibsen <[email protected]> Committed: Sun Mar 9 09:04:14 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/9b9e17d8/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/9b9e17d8/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
