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/08/20 19:05:31 UTC
[camel] 11/12: CAMEL-13870: Fast property configuration of Camel
endpoints. Work in progress.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch CAMEL-13870
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 0cd102598e0d605f045c0c56960df1e6452bf78e
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Aug 20 20:55:16 2019 +0200
CAMEL-13870: Fast property configuration of Camel endpoints. Work in progress.
---
.../component/disruptor/DisruptorComponent.java | 27 ++++---
.../component/disruptor/DisruptorEndpoint.java | 28 ++++---
.../component/docker/DockerConfiguration.java | 4 +-
.../camel/component/dropbox/DropboxEndpoint.java | 4 +
.../src/main/docs/ehcache-component.adoc | 4 +-
.../component/ehcache/EhcacheConfiguration.java | 16 ++--
.../camel/component/ehcache/EhcacheConsumer.java | 11 ++-
.../camel/component/ehcache/EhcacheProducer.java | 35 ++++++--
.../ehcache/EhcacheComponentConfigurationTest.java | 4 +-
.../dsl/EhcacheEndpointBuilderFactory.java | 94 ++--------------------
.../springboot/EhcacheComponentConfiguration.java | 12 +--
11 files changed, 100 insertions(+), 139 deletions(-)
diff --git a/components/camel-disruptor/src/main/java/org/apache/camel/component/disruptor/DisruptorComponent.java b/components/camel-disruptor/src/main/java/org/apache/camel/component/disruptor/DisruptorComponent.java
index f596dd0..5717fd7 100644
--- a/components/camel-disruptor/src/main/java/org/apache/camel/component/disruptor/DisruptorComponent.java
+++ b/components/camel-disruptor/src/main/java/org/apache/camel/component/disruptor/DisruptorComponent.java
@@ -93,18 +93,21 @@ public class DisruptorComponent extends DefaultComponent {
throw new IllegalArgumentException("The 'pollTimeout' argument is not supported by the Disruptor component");
}
- final DisruptorWaitStrategy waitStrategy = getAndRemoveParameter(parameters, "waitStrategy", DisruptorWaitStrategy.class, defaultWaitStrategy);
- final DisruptorProducerType producerType = getAndRemoveParameter(parameters, "producerType", DisruptorProducerType.class, defaultProducerType);
- final boolean multipleConsumers = getAndRemoveParameter(parameters, "multipleConsumers", boolean.class, defaultMultipleConsumers);
- final boolean blockWhenFull = getAndRemoveParameter(parameters, "blockWhenFull", boolean.class, defaultBlockWhenFull);
-
- final DisruptorReference disruptorReference = getOrCreateDisruptor(uri, remaining, size, producerType, waitStrategy);
- final DisruptorEndpoint disruptorEndpoint = new DisruptorEndpoint(uri, this, disruptorReference, concurrentConsumers, multipleConsumers, blockWhenFull);
- disruptorEndpoint.setWaitStrategy(waitStrategy);
- disruptorEndpoint.setProducerType(producerType);
- disruptorEndpoint.configureProperties(parameters);
-
- return disruptorEndpoint;
+ DisruptorWaitStrategy waitStrategy = getAndRemoveParameter(parameters, "waitStrategy", DisruptorWaitStrategy.class, defaultWaitStrategy);
+ DisruptorProducerType producerType = getAndRemoveParameter(parameters, "producerType", DisruptorProducerType.class, defaultProducerType);
+ boolean multipleConsumers = getAndRemoveParameter(parameters, "multipleConsumers", boolean.class, defaultMultipleConsumers);
+ boolean blockWhenFull = getAndRemoveParameter(parameters, "blockWhenFull", boolean.class, defaultBlockWhenFull);
+
+ DisruptorReference disruptorReference = getOrCreateDisruptor(uri, remaining, size, producerType, waitStrategy);
+ DisruptorEndpoint answer = new DisruptorEndpoint(uri, this, disruptorReference);
+ answer.setConcurrentConsumers(concurrentConsumers);
+ answer.setMultipleConsumers(multipleConsumers);
+ answer.setBlockWhenFull(blockWhenFull);
+ answer.setWaitStrategy(waitStrategy);
+ answer.setProducerType(producerType);
+ answer.configureProperties(parameters);
+
+ return answer;
}
private DisruptorReference getOrCreateDisruptor(final String uri, final String name, final int size,
diff --git a/components/camel-disruptor/src/main/java/org/apache/camel/component/disruptor/DisruptorEndpoint.java b/components/camel-disruptor/src/main/java/org/apache/camel/component/disruptor/DisruptorEndpoint.java
index 9b81e7f..d5dcdcd 100644
--- a/components/camel-disruptor/src/main/java/org/apache/camel/component/disruptor/DisruptorEndpoint.java
+++ b/components/camel-disruptor/src/main/java/org/apache/camel/component/disruptor/DisruptorEndpoint.java
@@ -61,9 +61,9 @@ public class DisruptorEndpoint extends DefaultEndpoint implements AsyncEndpoint,
@UriPath(description = "Name of queue") @Metadata(required = true)
private String name;
@UriParam(label = "consumer", defaultValue = "1")
- private final int concurrentConsumers;
+ private int concurrentConsumers;
@UriParam(label = "consumer")
- private final boolean multipleConsumers;
+ private boolean multipleConsumers;
@UriParam(label = "producer", defaultValue = "IfReplyExpected")
private WaitForTaskToComplete waitForTaskToComplete = WaitForTaskToComplete.IfReplyExpected;
@UriParam(label = "producer", defaultValue = "30000")
@@ -78,14 +78,10 @@ public class DisruptorEndpoint extends DefaultEndpoint implements AsyncEndpoint,
private DisruptorProducerType producerType;
public DisruptorEndpoint(final String endpointUri, final Component component,
- final DisruptorReference disruptorReference, final int concurrentConsumers,
- final boolean multipleConsumers, boolean blockWhenFull) throws Exception {
+ final DisruptorReference disruptorReference) {
super(endpointUri, component);
this.disruptorReference = disruptorReference;
this.name = disruptorReference.getName();
- this.concurrentConsumers = concurrentConsumers;
- this.multipleConsumers = multipleConsumers;
- this.blockWhenFull = blockWhenFull;
}
@ManagedAttribute(description = "Queue name")
@@ -108,14 +104,18 @@ public class DisruptorEndpoint extends DefaultEndpoint implements AsyncEndpoint,
return getDisruptor().getPendingExchangeCount();
}
- /**
- * Number of concurrent threads processing exchanges.
- */
@ManagedAttribute(description = "Number of concurrent consumers")
public int getConcurrentConsumers() {
return concurrentConsumers;
}
+ /**
+ * Number of concurrent threads processing exchanges.
+ */
+ public void setConcurrentConsumers(int concurrentConsumers) {
+ this.concurrentConsumers = concurrentConsumers;
+ }
+
@ManagedAttribute(description = "Option to specify whether the caller should wait for the async task to complete or not before continuing")
public WaitForTaskToComplete getWaitForTaskToComplete() {
return waitForTaskToComplete;
@@ -165,14 +165,18 @@ public class DisruptorEndpoint extends DefaultEndpoint implements AsyncEndpoint,
return isMultipleConsumers();
}
+ public boolean isMultipleConsumers() {
+ return multipleConsumers;
+ }
+
/**
* Specifies whether multiple consumers are allowed.
* If enabled, you can use Disruptor for Publish-Subscribe messaging.
* That is, you can send a message to the queue and have each consumer receive a copy of the message.
* When enabled, this option should be specified on every consumer endpoint.
*/
- public boolean isMultipleConsumers() {
- return multipleConsumers;
+ public void setMultipleConsumers(boolean multipleConsumers) {
+ this.multipleConsumers = multipleConsumers;
}
/**
diff --git a/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerConfiguration.java b/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerConfiguration.java
index dab3b54..b5ebf30 100644
--- a/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerConfiguration.java
+++ b/components/camel-docker/src/main/java/org/apache/camel/component/docker/DockerConfiguration.java
@@ -189,7 +189,7 @@ public class DockerConfiguration implements Cloneable {
this.maxPerRouteConnections = maxPerRouteConnections;
}
- public boolean isLoggingFilterEnabled() {
+ public boolean isLoggingFilter() {
return loggingFilter;
}
@@ -200,7 +200,7 @@ public class DockerConfiguration implements Cloneable {
this.loggingFilter = loggingFilterEnabled;
}
- public boolean isFollowRedirectFilterEnabled() {
+ public boolean isFollowRedirectFilter() {
return followRedirectFilter;
}
diff --git a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/DropboxEndpoint.java b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/DropboxEndpoint.java
index 07cfca3..379723b 100644
--- a/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/DropboxEndpoint.java
+++ b/components/camel-dropbox/src/main/java/org/apache/camel/component/dropbox/DropboxEndpoint.java
@@ -55,6 +55,10 @@ public class DropboxEndpoint extends DefaultEndpoint {
this.configuration = configuration;
}
+ public DropboxConfiguration getConfiguration() {
+ return configuration;
+ }
+
/**
* Create one of the camel producer available based on the configuration
* @return the camel producer
diff --git a/components/camel-ehcache/src/main/docs/ehcache-component.adoc b/components/camel-ehcache/src/main/docs/ehcache-component.adoc
index 7554c48..950b0af 100644
--- a/components/camel-ehcache/src/main/docs/ehcache-component.adoc
+++ b/components/camel-ehcache/src/main/docs/ehcache-component.adoc
@@ -98,9 +98,9 @@ with the following path and query parameters:
| *basicPropertyBinding* (advanced) | Whether the endpoint should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
| *configuration* (advanced) | The default cache configuration to be used to create caches. | | CacheConfiguration
| *configurations* (advanced) | A map of cache configuration to be used to create caches. | | Map
-| *keyType* (advanced) | The cache key type, default java.lang.Object | java.lang.Object | String
+| *keyType* (advanced) | The cache key type, default java.lang.Object | | String
| *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean
-| *valueType* (advanced) | The cache value type, default java.lang.Object | java.lang.Object | String
+| *valueType* (advanced) | The cache value type, default java.lang.Object | | String
|===
// endpoint options: END
// spring-boot-auto-configure options: START
diff --git a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheConfiguration.java b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheConfiguration.java
index d3922ce..df368a8 100644
--- a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheConfiguration.java
+++ b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheConfiguration.java
@@ -53,10 +53,10 @@ public class EhcacheConfiguration implements Cloneable {
private CacheConfiguration configuration;
@UriParam(label = "advanced")
private Map<String, CacheConfiguration> configurations;
- @UriParam(label = "advanced", javaType = "java.lang.String", defaultValue = "java.lang.Object")
- private Class<?> keyType;
- @UriParam(label = "advanced", javaType = "java.lang.String", defaultValue = "java.lang.Object")
- private Class<?> valueType;
+ @UriParam(label = "advanced")
+ private String keyType;
+ @UriParam(label = "advanced")
+ private String valueType;
@UriParam(label = "consumer", defaultValue = "ORDERED")
private EventOrdering eventOrdering = EventOrdering.ORDERED;
@UriParam(label = "consumer", defaultValue = "ASYNCHRONOUS")
@@ -260,25 +260,25 @@ public class EhcacheConfiguration implements Cloneable {
this.configurations.putAll(configurations);
}
- public Class<?> getKeyType() {
+ public String getKeyType() {
return keyType;
}
/**
* The cache key type, default "java.lang.Object"
*/
- public void setKeyType(Class<?> keyType) {
+ public void setKeyType(String keyType) {
this.keyType = keyType;
}
- public Class<?> getValueType() {
+ public String getValueType() {
return valueType;
}
/**
* The cache value type, default "java.lang.Object"
*/
- public void setValueType(Class<?> valueType) {
+ public void setValueType(String valueType) {
this.valueType = valueType;
}
diff --git a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheConsumer.java b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheConsumer.java
index df73f86..a6263c4 100644
--- a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheConsumer.java
+++ b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheConsumer.java
@@ -34,7 +34,16 @@ public class EhcacheConsumer extends DefaultConsumer implements CacheEventListen
this.configuration = configuration;
this.manager = endpoint.getManager();
- this.cache = manager.getCache(cacheName, configuration.getKeyType(), configuration.getValueType());
+
+ Class<?> kt = null;
+ if (configuration.getKeyType() != null) {
+ kt = getEndpoint().getCamelContext().getClassResolver().resolveClass(configuration.getKeyType());
+ }
+ Class<?> vt = null;
+ if (configuration.getValueType() != null) {
+ vt = getEndpoint().getCamelContext().getClassResolver().resolveClass(configuration.getValueType());
+ }
+ this.cache = manager.getCache(cacheName, kt, vt);
}
@Override
diff --git a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheProducer.java b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheProducer.java
index 0f8cea4..e5a4f94 100644
--- a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheProducer.java
+++ b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheProducer.java
@@ -32,11 +32,20 @@ public class EhcacheProducer extends HeaderSelectorProducer {
private final Cache cache;
public EhcacheProducer(EhcacheEndpoint endpoint, String cacheName, EhcacheConfiguration configuration) throws Exception {
- super(endpoint, EhcacheConstants.ACTION, () -> configuration.getAction());
+ super(endpoint, EhcacheConstants.ACTION, configuration::getAction);
this.configuration = configuration;
this.manager = endpoint.getManager();
- this.cache = manager.getCache(cacheName, configuration.getKeyType(), configuration.getValueType());
+
+ Class<?> kt = null;
+ if (configuration.getKeyType() != null) {
+ kt = getEndpoint().getCamelContext().getClassResolver().resolveClass(configuration.getKeyType());
+ }
+ Class<?> vt = null;
+ if (configuration.getValueType() != null) {
+ vt = getEndpoint().getCamelContext().getClassResolver().resolveClass(configuration.getValueType());
+ }
+ this.cache = manager.getCache(cacheName, kt, vt);
}
// ****************************
@@ -130,7 +139,13 @@ public class EhcacheProducer extends HeaderSelectorProducer {
// ****************************
private Object getKey(final Message message) throws Exception {
- Object value = message.getHeader(EhcacheConstants.KEY, cache.getRuntimeConfiguration().getKeyType());
+ Object value;
+ if (configuration.getKeyType() != null) {
+ Class<?> clazz = getEndpoint().getCamelContext().getClassResolver().resolveClass(configuration.getKeyType());
+ value = message.getHeader(EhcacheConstants.KEY, clazz);
+ } else {
+ value = message.getHeader(EhcacheConstants.KEY);
+ }
if (value == null) {
value = configuration.getKey();
}
@@ -145,10 +160,18 @@ public class EhcacheProducer extends HeaderSelectorProducer {
return value;
}
- private Object getValue(final Message message, final Class<?> type) throws Exception {
- Object value = message.getHeader(EhcacheConstants.VALUE, type);
+ @SuppressWarnings("unchecked")
+ private Object getValue(final Message message, final Object type) throws Exception {
+ Object value = message.getHeader(EhcacheConstants.VALUE);
if (value == null) {
- value = message.getBody(type);
+ if (type instanceof String) {
+ Class<?> clazz = getEndpoint().getCamelContext().getClassResolver().resolveClass((String) type);
+ value = message.getBody(clazz);
+ } else if (type instanceof Class) {
+ value = message.getBody((Class) type);
+ } else {
+ value = message.getBody();
+ }
}
if (value == null) {
diff --git a/components/camel-ehcache/src/test/java/org/apache/camel/component/ehcache/EhcacheComponentConfigurationTest.java b/components/camel-ehcache/src/test/java/org/apache/camel/component/ehcache/EhcacheComponentConfigurationTest.java
index bd450b4..01db7f5 100644
--- a/components/camel-ehcache/src/test/java/org/apache/camel/component/ehcache/EhcacheComponentConfigurationTest.java
+++ b/components/camel-ehcache/src/test/java/org/apache/camel/component/ehcache/EhcacheComponentConfigurationTest.java
@@ -39,8 +39,8 @@ public class EhcacheComponentConfigurationTest extends CamelTestSupport {
@BindToRegistry("ehcache")
public Component createEhcacheComponent() throws Exception {
EhcacheComponent component = new EhcacheComponent();
- component.getConfiguration().setKeyType(String.class);
- component.getConfiguration().setValueType(String.class);
+ component.getConfiguration().setKeyType("java.lang.String");
+ component.getConfiguration().setValueType("java.lang.String");
component.getConfiguration().setCacheManager(
CacheManagerBuilder.newCacheManagerBuilder()
.withCache(
diff --git a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/EhcacheEndpointBuilderFactory.java b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/EhcacheEndpointBuilderFactory.java
index f800339..9c29554 100644
--- a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/EhcacheEndpointBuilderFactory.java
+++ b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/EhcacheEndpointBuilderFactory.java
@@ -393,21 +393,7 @@ public interface EhcacheEndpointBuilderFactory {
/**
* The cache key type, default java.lang.Object.
*
- * The option is a: <code>java.lang.Class<java.lang.Object></code>
- * type.
- *
- * Group: advanced
- */
- default AdvancedEhcacheEndpointConsumerBuilder keyType(
- Class<Object> keyType) {
- setProperty("keyType", keyType);
- return this;
- }
- /**
- * The cache key type, default java.lang.Object.
- *
- * The option will be converted to a
- * <code>java.lang.Class<java.lang.Object></code> type.
+ * The option is a: <code>java.lang.String</code> type.
*
* Group: advanced
*/
@@ -444,21 +430,7 @@ public interface EhcacheEndpointBuilderFactory {
/**
* The cache value type, default java.lang.Object.
*
- * The option is a: <code>java.lang.Class<java.lang.Object></code>
- * type.
- *
- * Group: advanced
- */
- default AdvancedEhcacheEndpointConsumerBuilder valueType(
- Class<Object> valueType) {
- setProperty("valueType", valueType);
- return this;
- }
- /**
- * The cache value type, default java.lang.Object.
- *
- * The option will be converted to a
- * <code>java.lang.Class<java.lang.Object></code> type.
+ * The option is a: <code>java.lang.String</code> type.
*
* Group: advanced
*/
@@ -736,21 +708,7 @@ public interface EhcacheEndpointBuilderFactory {
/**
* The cache key type, default java.lang.Object.
*
- * The option is a: <code>java.lang.Class<java.lang.Object></code>
- * type.
- *
- * Group: advanced
- */
- default AdvancedEhcacheEndpointProducerBuilder keyType(
- Class<Object> keyType) {
- setProperty("keyType", keyType);
- return this;
- }
- /**
- * The cache key type, default java.lang.Object.
- *
- * The option will be converted to a
- * <code>java.lang.Class<java.lang.Object></code> type.
+ * The option is a: <code>java.lang.String</code> type.
*
* Group: advanced
*/
@@ -787,21 +745,7 @@ public interface EhcacheEndpointBuilderFactory {
/**
* The cache value type, default java.lang.Object.
*
- * The option is a: <code>java.lang.Class<java.lang.Object></code>
- * type.
- *
- * Group: advanced
- */
- default AdvancedEhcacheEndpointProducerBuilder valueType(
- Class<Object> valueType) {
- setProperty("valueType", valueType);
- return this;
- }
- /**
- * The cache value type, default java.lang.Object.
- *
- * The option will be converted to a
- * <code>java.lang.Class<java.lang.Object></code> type.
+ * The option is a: <code>java.lang.String</code> type.
*
* Group: advanced
*/
@@ -1002,20 +946,7 @@ public interface EhcacheEndpointBuilderFactory {
/**
* The cache key type, default java.lang.Object.
*
- * The option is a: <code>java.lang.Class<java.lang.Object></code>
- * type.
- *
- * Group: advanced
- */
- default AdvancedEhcacheEndpointBuilder keyType(Class<Object> keyType) {
- setProperty("keyType", keyType);
- return this;
- }
- /**
- * The cache key type, default java.lang.Object.
- *
- * The option will be converted to a
- * <code>java.lang.Class<java.lang.Object></code> type.
+ * The option is a: <code>java.lang.String</code> type.
*
* Group: advanced
*/
@@ -1050,20 +981,7 @@ public interface EhcacheEndpointBuilderFactory {
/**
* The cache value type, default java.lang.Object.
*
- * The option is a: <code>java.lang.Class<java.lang.Object></code>
- * type.
- *
- * Group: advanced
- */
- default AdvancedEhcacheEndpointBuilder valueType(Class<Object> valueType) {
- setProperty("valueType", valueType);
- return this;
- }
- /**
- * The cache value type, default java.lang.Object.
- *
- * The option will be converted to a
- * <code>java.lang.Class<java.lang.Object></code> type.
+ * The option is a: <code>java.lang.String</code> type.
*
* Group: advanced
*/
diff --git a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentConfiguration.java
index 230c4bc..11432b9 100644
--- a/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-ehcache-starter/src/main/java/org/apache/camel/component/ehcache/springboot/EhcacheComponentConfiguration.java
@@ -192,11 +192,11 @@ public class EhcacheComponentConfiguration
/**
* The cache key type, default "java.lang.Object"
*/
- private Class keyType = java.lang.Object.class;
+ private String keyType;
/**
* The cache value type, default "java.lang.Object"
*/
- private Class valueType = java.lang.Object.class;
+ private String valueType;
public String getConfigurationUri() {
return configurationUri;
@@ -298,19 +298,19 @@ public class EhcacheComponentConfiguration
this.configurations = configurations;
}
- public Class getKeyType() {
+ public String getKeyType() {
return keyType;
}
- public void setKeyType(Class keyType) {
+ public void setKeyType(String keyType) {
this.keyType = keyType;
}
- public Class getValueType() {
+ public String getValueType() {
return valueType;
}
- public void setValueType(Class valueType) {
+ public void setValueType(String valueType) {
this.valueType = valueType;
}
}