Author: davsclaus Date: Fri Jun 25 05:27:41 2010 New Revision: 957803 URL: http://svn.apache.org/viewvc?rev=957803&view=rev Log: CAMEL-2855: Added startDelayedSeconds option to quartz component to have the scheduler being started later. Can be used to ensure the scheduler is started after all the routes and whatnot has been initialized.
Added: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedTest.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=957803&r1=957802&r2=957803&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 Fri Jun 25 05:27:41 2010 @@ -55,6 +55,7 @@ public class QuartzComponent extends Def private SchedulerFactory factory; private Properties properties; private String propertiesFile; + private int startDelayedSeconds; public QuartzComponent() { } @@ -198,8 +199,13 @@ public class QuartzComponent extends Def scheduler = createScheduler(); } if (!scheduler.isStarted()) { - LOG.info("Starting Quartz scheduler: " + scheduler.getSchedulerName()); - scheduler.start(); + if (getStartDelayedSeconds() > 0) { + LOG.info("Starting Quartz scheduler: " + scheduler.getSchedulerName() + " delayed: " + getStartDelayedSeconds() + " seconds."); + scheduler.startDelayed(getStartDelayedSeconds()); + } else { + LOG.info("Starting Quartz scheduler: " + scheduler.getSchedulerName()); + scheduler.start(); + } } return scheduler; } @@ -224,6 +230,14 @@ public class QuartzComponent extends Def this.propertiesFile = propertiesFile; } + public int getStartDelayedSeconds() { + return startDelayedSeconds; + } + + public void setStartDelayedSeconds(int startDelayedSeconds) { + this.startDelayedSeconds = startDelayedSeconds; + } + // Implementation methods // ------------------------------------------------------------------------- Added: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedTest.java?rev=957803&view=auto ============================================================================== --- camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedTest.java (added) +++ camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedTest.java Fri Jun 25 05:27:41 2010 @@ -0,0 +1,55 @@ +/** + * 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 org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.apache.camel.util.StopWatch; +import org.junit.Test; + +/** + * @version $Revision$ + */ +public class QuartzStartDelayedTest extends CamelTestSupport { + + @Test + public void testStartDelayed() throws Exception { + StopWatch watch = new StopWatch(); + + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMessageCount(2); + + assertMockEndpointsSatisfied(); + + long time = watch.stop(); + assertTrue("Should take longer than 3 seconds, was: " + time + " millis.", time > 2500); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + QuartzComponent quartz = context.getComponent("quartz", QuartzComponent.class); + quartz.setStartDelayedSeconds(3); + + from("quartz://myGroup/myTimerName?trigger.repeatInterval=2&trigger.repeatCount=1").routeId("myRoute").to("mock:result"); + } + }; + } +} Propchange: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzStartDelayedTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date