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 2019/12/09 12:30:48 UTC

[camel] branch master updated: CAMEL-14270: camel-quartz - Allow to configure quartz properties via spring boot autoconfiguraiton

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 4d09509  CAMEL-14270: camel-quartz - Allow to configure quartz properties via spring boot autoconfiguraiton
4d09509 is described below

commit 4d09509f171197b4ee9ffa7405d3d787a191a337
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Dec 9 13:14:54 2019 +0100

    CAMEL-14270: camel-quartz - Allow to configure quartz properties via spring boot autoconfiguraiton
---
 .../src/main/docs/quartz-component.adoc            | 10 ++++---
 .../camel/component/quartz/QuartzComponent.java    | 31 +++++++++++++++++++---
 .../springboot/QuartzComponentConfiguration.java   | 23 ++++++++++++----
 3 files changed, 51 insertions(+), 13 deletions(-)

diff --git a/components/camel-quartz/src/main/docs/quartz-component.adoc b/components/camel-quartz/src/main/docs/quartz-component.adoc
index 594075a..5d09aa3 100644
--- a/components/camel-quartz/src/main/docs/quartz-component.adoc
+++ b/components/camel-quartz/src/main/docs/quartz-component.adoc
@@ -48,7 +48,7 @@ You can append query options to the URI in the following format,
 
 
 // component options: START
-The Quartz component supports 13 options, which are listed below.
+The Quartz component supports 14 options, which are listed below.
 
 
 
@@ -59,7 +59,8 @@ The Quartz component supports 13 options, which are listed below.
 | *startDelayedSeconds* (scheduler) | Seconds to wait before starting the quartz scheduler. |  | int
 | *prefixJobNameWith EndpointId* (consumer) | Whether to prefix the quartz job with the endpoint id. This option is default false. | false | boolean
 | *enableJmx* (consumer) | Whether to enable Quartz JMX which allows to manage the Quartz scheduler from JMX. This options is default true | true | boolean
-| *properties* (consumer) | Properties to configure the Quartz scheduler. |  | Properties
+| *propertiesRef* (consumer) | References to an existing Properties or Map to lookup in the registry to use for configuring quartz. |  | String
+| *properties* (consumer) | Properties to configure the Quartz scheduler. |  | Map
 | *propertiesFile* (consumer) | File name of the properties to load from the classpath |  | String
 | *prefixInstanceName* (consumer) | Whether to prefix the Quartz Scheduler instance name with the CamelContext name. This is enabled by default, to let each CamelContext use its own Quartz scheduler instance by default. You can set this option to false to reuse Quartz scheduler instances between multiple CamelContext's. | true | boolean
 | *interruptJobsOn Shutdown* (scheduler) | Whether to interrupt jobs on shutdown which forces the scheduler to shutdown quicker and attempt to interrupt any running jobs. If this is enabled then any running jobs can fail due to being interrupted. | false | boolean
@@ -138,7 +139,7 @@ When using Spring Boot make sure to use the following Maven dependency to have s
 ----
 
 
-The component supports 14 options, which are listed below.
+The component supports 15 options, which are listed below.
 
 
 
@@ -154,8 +155,9 @@ The component supports 14 options, which are listed below.
 | *camel.component.quartz.lazy-start-producer* | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed the [...]
 | *camel.component.quartz.prefix-instance-name* | Whether to prefix the Quartz Scheduler instance name with the CamelContext name. This is enabled by default, to let each CamelContext use its own Quartz scheduler instance by default. You can set this option to false to reuse Quartz scheduler instances between multiple CamelContext's. | true | Boolean
 | *camel.component.quartz.prefix-job-name-with-endpoint-id* | Whether to prefix the quartz job with the endpoint id. This option is default false. | false | Boolean
-| *camel.component.quartz.properties* | Properties to configure the Quartz scheduler. The option is a java.util.Properties type. |  | String
+| *camel.component.quartz.properties* | Properties to configure the Quartz scheduler. |  | Map
 | *camel.component.quartz.properties-file* | File name of the properties to load from the classpath |  | String
+| *camel.component.quartz.properties-ref* | References to an existing Properties or Map to lookup in the registry to use for configuring quartz. |  | String
 | *camel.component.quartz.scheduler* | To use the custom configured Quartz scheduler, instead of creating a new Scheduler. The option is a org.quartz.Scheduler type. |  | String
 | *camel.component.quartz.scheduler-factory* | To use the custom SchedulerFactory which is used to create the Scheduler. The option is a org.quartz.SchedulerFactory type. |  | String
 | *camel.component.quartz.start-delayed-seconds* | Seconds to wait before starting the quartz scheduler. |  | Integer
diff --git a/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java b/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
index 7969931..4796373 100644
--- a/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
+++ b/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.quartz;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URI;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -28,6 +29,7 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.ExtendedStartupListener;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.annotations.Component;
+import org.apache.camel.support.CamelContextHelper;
 import org.apache.camel.support.DefaultComponent;
 import org.apache.camel.support.ResourceHelper;
 import org.apache.camel.util.IOHelper;
@@ -52,7 +54,8 @@ public class QuartzComponent extends DefaultComponent implements ExtendedStartup
     private Scheduler scheduler;
     @Metadata(label = "advanced")
     private SchedulerFactory schedulerFactory;
-    private Properties properties;
+    private String propertiesRef;
+    private Map properties;
     private String propertiesFile;
     @Metadata(label = "scheduler")
     private int startDelayedSeconds;
@@ -123,14 +126,25 @@ public class QuartzComponent extends DefaultComponent implements ExtendedStartup
         this.enableJmx = enableJmx;
     }
 
-    public Properties getProperties() {
+    public String getPropertiesRef() {
+        return propertiesRef;
+    }
+
+    /**
+     * References to an existing {@link Properties} or {@link Map} to lookup in the registry to use for configuring quartz.
+     */
+    public void setPropertiesRef(String propertiesRef) {
+        this.propertiesRef = propertiesRef;
+    }
+
+    public Map getProperties() {
         return properties;
     }
 
     /**
      * Properties to configure the Quartz scheduler.
      */
-    public void setProperties(Properties properties) {
+    public void setProperties(Map properties) {
         this.properties = properties;
     }
 
@@ -278,7 +292,16 @@ public class QuartzComponent extends DefaultComponent implements ExtendedStartup
     }
 
     private Properties loadProperties() throws SchedulerException {
-        Properties answer = getProperties();
+        Properties answer = null;
+        if (getProperties() != null) {
+            answer = new Properties();
+            answer.putAll(getProperties());
+        }
+        if (answer == null && getPropertiesRef() != null) {
+            Map map = CamelContextHelper.mandatoryLookup(getCamelContext(), getPropertiesRef(), Map.class);
+            answer = new Properties();
+            answer.putAll(map);
+        }
         if (answer == null && getPropertiesFile() != null) {
             log.info("Loading Quartz properties file from: {}", getPropertiesFile());
             InputStream is = null;
diff --git a/platforms/spring-boot/components-starter/camel-quartz-starter/src/main/java/org/apache/camel/component/quartz/springboot/QuartzComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-quartz-starter/src/main/java/org/apache/camel/component/quartz/springboot/QuartzComponentConfiguration.java
index 6dafec7..4c2bf0a 100644
--- a/platforms/spring-boot/components-starter/camel-quartz-starter/src/main/java/org/apache/camel/component/quartz/springboot/QuartzComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-quartz-starter/src/main/java/org/apache/camel/component/quartz/springboot/QuartzComponentConfiguration.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.quartz.springboot;
 
+import java.util.Map;
 import javax.annotation.Generated;
 import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
 import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -56,10 +57,14 @@ public class QuartzComponentConfiguration
      */
     private Boolean enableJmx = true;
     /**
-     * Properties to configure the Quartz scheduler. The option is a
-     * java.util.Properties type.
+     * References to an existing Properties or Map to lookup in the registry to
+     * use for configuring quartz.
      */
-    private String properties;
+    private String propertiesRef;
+    /**
+     * Properties to configure the Quartz scheduler.
+     */
+    private Map properties;
     /**
      * File name of the properties to load from the classpath
      */
@@ -147,11 +152,19 @@ public class QuartzComponentConfiguration
         this.enableJmx = enableJmx;
     }
 
-    public String getProperties() {
+    public String getPropertiesRef() {
+        return propertiesRef;
+    }
+
+    public void setPropertiesRef(String propertiesRef) {
+        this.propertiesRef = propertiesRef;
+    }
+
+    public Map getProperties() {
         return properties;
     }
 
-    public void setProperties(String properties) {
+    public void setProperties(Map properties) {
         this.properties = properties;
     }