camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r957419 - in /camel/trunk/components/camel-quartz/src: main/java/org/apache/camel/component/quartz/ test/java/org/apache/camel/component/quartz/ test/resources/org/apache/camel/component/quartz/
Date Thu, 24 Jun 2010 05:17:48 GMT
Author: davsclaus
Date: Thu Jun 24 05:17:48 2010
New Revision: 957419

URL: http://svn.apache.org/viewvc?rev=957419&view=rev
Log:
CAMEL-2844: Added options on quartz component to specify a custom quartz.properties to be
used.

Added:
    camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzPropertiesTest.java
  (with props)
    camel/trunk/components/camel-quartz/src/test/resources/org/apache/camel/component/quartz/
    camel/trunk/components/camel-quartz/src/test/resources/org/apache/camel/component/quartz/myquartz.properties
  (with props)
Modified:
    camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/CamelJob.java
    camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
    camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/StatefulCamelJob.java
    camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzComponentTest.java
    camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzRouteFireNowTest.java
    camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzTwoCamelContextTest.java
    camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/StatefulQuartzRouteTest.java

Modified: camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/CamelJob.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/CamelJob.java?rev=957419&r1=957418&r2=957419&view=diff
==============================================================================
--- camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/CamelJob.java
(original)
+++ camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/CamelJob.java
Thu Jun 24 05:17:48 2010
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.quartz;
 
+import java.io.Serializable;
+
 import org.quartz.Job;
 import org.quartz.JobExecutionContext;
 import org.quartz.JobExecutionException;
@@ -23,7 +25,7 @@ import org.quartz.JobExecutionException;
 /**
  * @version $Revision$
  */
-public class CamelJob implements Job {
+public class CamelJob implements Job, Serializable {
 
     public void execute(JobExecutionContext context) throws JobExecutionException {
         QuartzEndpoint endpoint = (QuartzEndpoint) context.getJobDetail().getJobDataMap().get(QuartzConstants.QUARTZ_ENDPOINT);

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=957419&r1=957418&r2=957419&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
Thu Jun 24 05:17:48 2010
@@ -16,10 +16,13 @@
  */
 package org.apache.camel.component.quartz;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.net.URI;
 import java.text.ParseException;
 import java.util.Date;
 import java.util.Map;
+import java.util.Properties;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.camel.CamelContext;
@@ -42,7 +45,7 @@ import org.quartz.impl.StdSchedulerFacto
  * <p/>
  * For a brief tutorial on setting cron expression see
  * <a href="http://www.opensymphony.com/quartz/wikidocs/CronTriggers%20Tutorial.html">Quartz
cron tutorial</a>.
- * 
+ *
  * @version $Revision:520964 $
  */
 public class QuartzComponent extends DefaultComponent {
@@ -50,6 +53,8 @@ public class QuartzComponent extends Def
     private static final AtomicInteger JOBS = new AtomicInteger();
     private static Scheduler scheduler;
     private SchedulerFactory factory;
+    private Properties properties;
+    private String propertiesFile;
 
     public QuartzComponent() {
     }
@@ -82,7 +87,7 @@ public class QuartzComponent extends Def
 
         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)) {
@@ -101,7 +106,7 @@ public class QuartzComponent extends Def
 
         trigger.setName(name);
         trigger.setGroup(group);
-        
+
         setProperties(trigger, triggerParameters);
         setProperties(answer.getJobDetail(), jobParameters);
 
@@ -145,17 +150,17 @@ public class QuartzComponent extends Def
         JOBS.incrementAndGet();
 
         if (getScheduler().getTrigger(trigger.getName(), trigger.getGroup()) == null) {
-        	if (LOG.isDebugEnabled()) {
-        		LOG.debug("Adding job using trigger: " + trigger.getGroup() + "/" + trigger.getName());
-        	}
-        	getScheduler().scheduleJob(job, trigger);
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Adding job using trigger: " + trigger.getGroup() + "/" + trigger.getName());
+            }
+            getScheduler().scheduleJob(job, trigger);
         } else {
-        	if (LOG.isDebugEnabled()) {
-        		LOG.debug("Resuming job using trigger: " + trigger.getGroup() + "/" + trigger.getName());
-        	}
-        	getScheduler().resumeTrigger(trigger.getName(), trigger.getGroup());
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Resuming job using trigger: " + trigger.getGroup() + "/" + trigger.getName());
+            }
+            getScheduler().resumeTrigger(trigger.getName(), trigger.getGroup());
         }
-        
+
     }
 
     public void removeJob(Trigger trigger) throws SchedulerException {
@@ -169,7 +174,8 @@ public class QuartzComponent extends Def
 
     // Properties
     // -------------------------------------------------------------------------
-    public SchedulerFactory getFactory() {
+
+    public SchedulerFactory getFactory() throws SchedulerException {
         if (factory == null) {
             factory = createSchedulerFactory();
         }
@@ -184,7 +190,7 @@ public class QuartzComponent extends Def
         if (scheduler == null) {
             scheduler = createScheduler();
         }
-        if (!scheduler.isStarted()) {            
+        if (!scheduler.isStarted()) {
             LOG.info("Starting Quartz scheduler: " + scheduler.getSchedulerName());
             scheduler.start();
         }
@@ -195,10 +201,50 @@ public class QuartzComponent extends Def
         QuartzComponent.scheduler = scheduler;
     }
 
+    public Properties getProperties() {
+        return properties;
+    }
+
+    public void setProperties(Properties properties) {
+        this.properties = properties;
+    }
+
+    public String getPropertiesFile() {
+        return propertiesFile;
+    }
+
+    public void setPropertiesFile(String propertiesFile) {
+        this.propertiesFile = propertiesFile;
+    }
+
     // Implementation methods
     // -------------------------------------------------------------------------
-    protected SchedulerFactory createSchedulerFactory() {
-        return new StdSchedulerFactory();
+
+    protected Properties loadProperties() throws SchedulerException {
+        Properties answer = getProperties();
+        if (answer == null && getPropertiesFile() != null) {
+            LOG.info("Loading Quartz properties file from classpath: " + getPropertiesFile());
+            InputStream is = getCamelContext().getClassResolver().loadResourceAsStream(getPropertiesFile());
+            if (is == null) {
+                throw new SchedulerException("Quartz properties file not found in classpath:
" + getPropertiesFile());
+            }
+            answer = new Properties();
+            try {
+                answer.load(is);
+            } catch (IOException e) {
+                throw new SchedulerException("Error loading Quartz properties file from:
" + getPropertiesFile(), e);
+            }
+        }
+        return answer;
+    }
+
+    protected SchedulerFactory createSchedulerFactory() throws SchedulerException {
+        Properties prop = loadProperties();
+        if (prop != null) {
+            return new StdSchedulerFactory(prop);
+        } else {
+            return new StdSchedulerFactory();
+        }
     }
 
     protected Scheduler createScheduler() throws SchedulerException {

Modified: camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/StatefulCamelJob.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/StatefulCamelJob.java?rev=957419&r1=957418&r2=957419&view=diff
==============================================================================
--- camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/StatefulCamelJob.java
(original)
+++ camel/trunk/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/StatefulCamelJob.java
Thu Jun 24 05:17:48 2010
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.quartz;
 
+import java.io.Serializable;
+
 import org.apache.camel.CamelContext;
 import org.quartz.JobExecutionContext;
 import org.quartz.JobExecutionException;
@@ -26,7 +28,7 @@ import org.quartz.StatefulJob;
 /**
  * Stateful job
  */
-public class StatefulCamelJob implements StatefulJob {
+public class StatefulCamelJob implements StatefulJob, Serializable {
 
     public void execute(final JobExecutionContext context) throws JobExecutionException {
         SchedulerContext schedulerContext;

Modified: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzComponentTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzComponentTest.java?rev=957419&r1=957418&r2=957419&view=diff
==============================================================================
--- camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzComponentTest.java
(original)
+++ camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzComponentTest.java
Thu Jun 24 05:17:48 2010
@@ -28,7 +28,7 @@ import org.quartz.impl.StdSchedulerFacto
 public class QuartzComponentTest extends CamelTestSupport {
 
     @Test
-    public void testQuartzComponentCustomScheuduler() throws Exception {
+    public void testQuartzComponentCustomScheduler() throws Exception {
         QuartzComponent comp = new QuartzComponent();
         comp.setCamelContext(context);
 

Added: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzPropertiesTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzPropertiesTest.java?rev=957419&view=auto
==============================================================================
--- camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzPropertiesTest.java
(added)
+++ camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzPropertiesTest.java
Thu Jun 24 05:17:48 2010
@@ -0,0 +1,85 @@
+/**
+ * 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.io.InputStream;
+import java.util.Properties;
+
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+import org.quartz.SchedulerException;
+
+/**
+ * @version $Revision$
+ */
+public class QuartzPropertiesTest extends CamelTestSupport {
+
+    private QuartzComponent quartz;
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Override
+    public void tearDown() throws Exception {
+        quartz.stop();
+        super.tearDown();
+    }
+
+    @Test
+    public void testQuartzPropertiesFile() throws Exception {
+        quartz = context.getComponent("quartz", QuartzComponent.class);
+
+        quartz.setPropertiesFile("org/apache/camel/component/quartz/myquartz.properties");
+
+        quartz.start();
+
+        assertEquals("MyScheduler", quartz.getScheduler().getSchedulerName());
+        assertEquals("2", quartz.getScheduler().getSchedulerInstanceId());
+    }
+
+    @Test
+    public void testQuartzPropertiesFileNotFound() throws Exception {
+        quartz = context.getComponent("quartz", QuartzComponent.class);
+
+        quartz.setPropertiesFile("doesnotexist.properties");
+
+        try {
+            quartz.start();
+            fail("Should have thrown exception");
+        } catch (SchedulerException e) {
+            assertEquals("Quartz properties file not found in classpath: doesnotexist.properties",
e.getMessage());
+        }
+    }
+
+    @Test
+    public void testQuartzProperties() throws Exception {
+        quartz = context.getComponent("quartz", QuartzComponent.class);
+
+        Properties prop = new Properties();
+        InputStream is = context.getClassResolver().loadResourceAsStream("org/apache/camel/component/quartz/myquartz.properties");
+        prop.load(is);
+        quartz.setProperties(prop);
+
+        quartz.start();
+
+        assertEquals("MyScheduler", quartz.getScheduler().getSchedulerName());
+        assertEquals("2", quartz.getScheduler().getSchedulerInstanceId());
+    }
+
+}

Propchange: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzPropertiesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzPropertiesTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 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=957419&r1=957418&r2=957419&view=diff
==============================================================================
--- camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzRouteFireNowTest.java
(original)
+++ camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzRouteFireNowTest.java
Thu Jun 24 05:17:48 2010
@@ -16,15 +16,7 @@
  */
 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$

Modified: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzTwoCamelContextTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzTwoCamelContextTest.java?rev=957419&r1=957418&r2=957419&view=diff
==============================================================================
--- camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzTwoCamelContextTest.java
(original)
+++ camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzTwoCamelContextTest.java
Thu Jun 24 05:17:48 2010
@@ -16,7 +16,6 @@
  */
 package org.apache.camel.component.quartz;
 
-import junit.framework.TestCase;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.impl.DefaultCamelContext;

Modified: camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/StatefulQuartzRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/StatefulQuartzRouteTest.java?rev=957419&r1=957418&r2=957419&view=diff
==============================================================================
--- camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/StatefulQuartzRouteTest.java
(original)
+++ camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/StatefulQuartzRouteTest.java
Thu Jun 24 05:17:48 2010
@@ -26,7 +26,7 @@ import org.apache.camel.test.junit4.Came
 import org.junit.Test;
 
 /**
- *
+ * @version $Revision$
  */
 public class StatefulQuartzRouteTest extends CamelTestSupport {
     protected MockEndpoint resultEndpoint;

Added: camel/trunk/components/camel-quartz/src/test/resources/org/apache/camel/component/quartz/myquartz.properties
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-quartz/src/test/resources/org/apache/camel/component/quartz/myquartz.properties?rev=957419&view=auto
==============================================================================
--- camel/trunk/components/camel-quartz/src/test/resources/org/apache/camel/component/quartz/myquartz.properties
(added)
+++ camel/trunk/components/camel-quartz/src/test/resources/org/apache/camel/component/quartz/myquartz.properties
Thu Jun 24 05:17:48 2010
@@ -0,0 +1,9 @@
+org.quartz.scheduler.instanceName = MyScheduler
+org.quartz.scheduler.instanceId = 2
+org.quartz.scheduler.rmi.export = false
+org.quartz.scheduler.rmi.proxy = false
+
+org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
+org.quartz.threadPool.threadCount = 3
+
+org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
\ No newline at end of file

Propchange: camel/trunk/components/camel-quartz/src/test/resources/org/apache/camel/component/quartz/myquartz.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-quartz/src/test/resources/org/apache/camel/component/quartz/myquartz.properties
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-quartz/src/test/resources/org/apache/camel/component/quartz/myquartz.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message