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:25 UTC
[camel] 05/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 fd3d33b6c864599e44086724b3d53dd96bec5fc0
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Aug 20 12:47:57 2019 +0200
CAMEL-13870: Fast property configuration of Camel endpoints. Work in progress.
---
.../org/apache/camel/component/file/FileEndpoint.java | 4 ++--
.../camel/component/file/GenericFileEndpoint.java | 8 ++++++++
.../org/apache/camel/component/mock/MockEndpoint.java | 18 +++++++++++++++++-
.../apache/camel/component/timer/TimerEndpoint.java | 16 ++++++++++------
.../org/apache/camel/support/DefaultComponent.java | 5 +++++
.../apache/camel/support/PropertyBindingSupport.java | 18 +++++++++++++++---
.../camel/tools/apt/EndpointAnnotationProcessor.java | 13 ++++++++-----
.../tools/apt/EndpointPropertyConfigurerGenerator.java | 18 ++++--------------
8 files changed, 69 insertions(+), 31 deletions(-)
diff --git a/components/camel-file/src/main/java/org/apache/camel/component/file/FileEndpoint.java b/components/camel-file/src/main/java/org/apache/camel/component/file/FileEndpoint.java
index e1a8ef2..29fe0a1 100644
--- a/components/camel-file/src/main/java/org/apache/camel/component/file/FileEndpoint.java
+++ b/components/camel-file/src/main/java/org/apache/camel/component/file/FileEndpoint.java
@@ -411,7 +411,7 @@ public class FileEndpoint extends GenericFileEndpoint<File> {
* Specify the file permissions which is sent by the producer, the chmod value must be between 000 and 777;
* If there is a leading digit like in 0755 we will ignore it.
*/
- public void setChmod(String chmod) throws Exception {
+ public void setChmod(String chmod) {
if (ObjectHelper.isNotEmpty(chmod) && chmodPermissionsAreValid(chmod)) {
this.chmod = chmod.trim();
} else {
@@ -472,7 +472,7 @@ public class FileEndpoint extends GenericFileEndpoint<File> {
* Specify the directory permissions used when the producer creates missing directories, the chmod value must be between 000 and 777;
* If there is a leading digit like in 0755 we will ignore it.
*/
- public void setChmodDirectory(String chmodDirectory) throws Exception {
+ public void setChmodDirectory(String chmodDirectory) {
if (ObjectHelper.isNotEmpty(chmodDirectory) && chmodPermissionsAreValid(chmodDirectory)) {
this.chmodDirectory = chmodDirectory.trim();
} else {
diff --git a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
index 58aa43cf..09ef430 100644
--- a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
+++ b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
@@ -661,6 +661,10 @@ public abstract class GenericFileEndpoint<T> extends ScheduledPollEndpoint imple
return idempotent != null;
}
+ public Boolean getIdempotent() {
+ return idempotent;
+ }
+
/**
* Option to use the Idempotent Consumer EIP pattern to let Camel skip already processed files.
* Will by default use a memory based LRUCache that holds 1000 entries. If noop=true then idempotent will be enabled
@@ -1003,6 +1007,10 @@ public abstract class GenericFileEndpoint<T> extends ScheduledPollEndpoint imple
this.readLockRemoveOnCommit = readLockRemoveOnCommit;
}
+ public int getReadLockIdempotentReleaseDelay() {
+ return readLockIdempotentReleaseDelay;
+ }
+
/**
* Whether to delay the release task for a period of millis.
* <p/>
diff --git a/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockEndpoint.java b/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
index 21dcad5..485b431 100644
--- a/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
+++ b/components/camel-mock/src/main/java/org/apache/camel/component/mock/MockEndpoint.java
@@ -499,6 +499,10 @@ public class MockEndpoint extends DefaultEndpoint implements BrowsableEndpoint,
setExpectedMessageCount(expectedCount);
}
+ public long getAssertPeriod() {
+ return assertPeriod;
+ }
+
/**
* Sets a grace period after which the mock endpoint will re-assert
* to ensure the preliminary assertion is still valid.
@@ -1293,6 +1297,10 @@ public class MockEndpoint extends DefaultEndpoint implements BrowsableEndpoint,
this.resultWaitTime = resultWaitTime;
}
+ public long getResultMinimumWaitTime() {
+ return resultMinimumWaitTime;
+ }
+
/**
* Sets the minimum expected amount of time (in millis) the {@link #assertIsSatisfied()} will
* wait on a latch until it is satisfied
@@ -1363,6 +1371,10 @@ public class MockEndpoint extends DefaultEndpoint implements BrowsableEndpoint,
this.reporter = reporter;
}
+ public int getRetainFirst() {
+ return retainFirst;
+ }
+
/**
* Specifies to only retain the first n'th number of received {@link Exchange}s.
* <p/>
@@ -1391,6 +1403,10 @@ public class MockEndpoint extends DefaultEndpoint implements BrowsableEndpoint,
this.retainFirst = retainFirst;
}
+ public int getRetainLast() {
+ return retainLast;
+ }
+
/**
* Specifies to only retain the last n'th number of received {@link Exchange}s.
* <p/>
@@ -1419,7 +1435,7 @@ public class MockEndpoint extends DefaultEndpoint implements BrowsableEndpoint,
this.retainLast = retainLast;
}
- public int isReportGroup() {
+ public int getReportGroup() {
return reportGroup;
}
diff --git a/components/camel-timer/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java b/components/camel-timer/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java
index 236dbb9..8cc57f8 100644
--- a/components/camel-timer/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java
+++ b/components/camel-timer/src/main/java/org/apache/camel/component/timer/TimerEndpoint.java
@@ -225,12 +225,8 @@ public class TimerEndpoint extends DefaultEndpoint implements MultipleConsumersS
this.pattern = pattern;
}
- public Timer getTimer(TimerConsumer consumer) {
- if (timer != null) {
- // use custom timer
- return timer;
- }
- return getComponent().getTimer(consumer);
+ public Timer getTimer() {
+ return timer;
}
/**
@@ -240,6 +236,14 @@ public class TimerEndpoint extends DefaultEndpoint implements MultipleConsumersS
this.timer = timer;
}
+ public Timer getTimer(TimerConsumer consumer) {
+ if (timer != null) {
+ // use custom timer
+ return timer;
+ }
+ return getComponent().getTimer(consumer);
+ }
+
public void removeTimer(TimerConsumer consumer) {
if (timer == null) {
// only remove timer if we are not using a custom timer
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/DefaultComponent.java b/core/camel-support/src/main/java/org/apache/camel/support/DefaultComponent.java
index 866f9a6..1b15a29 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/DefaultComponent.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/DefaultComponent.java
@@ -43,6 +43,7 @@ import org.apache.camel.spi.PropertyConfigurer;
import org.apache.camel.spi.PropertyConfigurerAware;
import org.apache.camel.support.service.ServiceSupport;
import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.StringHelper;
import org.apache.camel.util.URISupport;
import org.apache.camel.util.UnsafeUriCharactersEncoder;
import org.apache.camel.util.function.Suppliers;
@@ -333,6 +334,10 @@ public abstract class DefaultComponent extends ServiceSupport implements Compone
org.apache.camel.spi.annotations.Component ann = ObjectHelper.getAnnotation(this, org.apache.camel.spi.annotations.Component.class);
if (ann != null) {
String name = ann.value();
+ // just grab first scheme name if the component has scheme alias (eg http,https)
+ if (name.contains(",")) {
+ name = StringHelper.before(name, ",");
+ }
try {
Optional<Class<?>> clazz = getCamelContext().getExtension(ExtendedCamelContext.class).getFactoryFinder(RESOURCE_PATH)
.findOptionalClass(name + "-endpoint", null);
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
index 11ffbcc..4a43e24 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java
@@ -33,6 +33,7 @@ import org.apache.camel.PropertyBindingException;
import org.apache.camel.spi.PropertyConfigurer;
import org.apache.camel.util.StringHelper;
+import static org.apache.camel.support.EndpointHelper.isReferenceParameter;
import static org.apache.camel.support.IntrospectionSupport.findSetterMethods;
import static org.apache.camel.util.ObjectHelper.isNotEmpty;
@@ -466,12 +467,23 @@ public final class PropertyBindingSupport {
Object value = entry.getValue();
if (writeProperties.containsKey(key)) {
- // TODO: reference
- // TODO: o
+ // support reference parameters
+ if (value instanceof String) {
+ String text = (String) value;
+ if (isReferenceParameter(text)) {
+ if (text.startsWith("#bean:")) {
+ text = text.substring(6);
+ } else {
+ text = text.substring(1);
+ }
+ value = CamelContextHelper.mandatoryLookup(camelContext, text);
+ }
+ }
+ // TODO: that thing with boolean and from string value true|false
writeProperties.get(key).accept(value);
if (removeParameter) {
- properties.remove(key);
+ iter.remove();
rc = true;
}
}
diff --git a/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java b/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java
index 361bcef..ba3c1ff 100644
--- a/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java
+++ b/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java
@@ -116,14 +116,14 @@ public class EndpointAnnotationProcessor extends AbstractCamelAnnotationProcesso
String packageName = name.substring(0, name.lastIndexOf("."));
String fileName = alias + ".json";
processFile(processingEnv, packageName, fileName,
- writer -> writeJSonSchemeDocumentation(writer, roundEnv, classElement, uriEndpoint, aliasTitle, alias, extendsAlias, label, schemes));
+ writer -> writeJSonSchemeAndPropertyConfigurer(writer, roundEnv, classElement, uriEndpoint, aliasTitle, alias, extendsAlias, label, schemes));
}
}
}
}
- protected void writeJSonSchemeDocumentation(PrintWriter writer, RoundEnvironment roundEnv, TypeElement classElement, UriEndpoint uriEndpoint,
- String title, String scheme, String extendsScheme, String label, String[] schemes) {
+ protected void writeJSonSchemeAndPropertyConfigurer(PrintWriter writer, RoundEnvironment roundEnv, TypeElement classElement, UriEndpoint uriEndpoint,
+ String title, String scheme, String extendsScheme, String label, String[] schemes) {
// gather component information
ComponentModel componentModel = findComponentProperties(roundEnv, uriEndpoint, classElement, title, scheme, extendsScheme, label);
@@ -180,8 +180,11 @@ public class EndpointAnnotationProcessor extends AbstractCamelAnnotationProcesso
String cn = en + "Configurer";
String fqn = pn + "." + cn;
- EndpointPropertyConfigurerGenerator.generatePropertyConfigurer(processingEnv, parent, pn, cn, fqn, en, fqen, endpointPaths, endpointOptions);
- EndpointPropertyConfigurerGenerator.generateMetaInfConfigurer(processingEnv, componentModel.getScheme() + "-endpoint", fqn);
+ // only generate this once for the first scheme
+ if (schemes == null || schemes[0].equals(scheme)) {
+ EndpointPropertyConfigurerGenerator.generatePropertyConfigurer(processingEnv, parent, pn, cn, fqn, en, fqen, endpointOptions);
+ EndpointPropertyConfigurerGenerator.generateMetaInfConfigurer(processingEnv, componentModel.getScheme() + "-endpoint", fqn);
+ }
}
public String createParameterJsonSchema(ComponentModel componentModel, Set<ComponentOption> componentOptions,
diff --git a/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointPropertyConfigurerGenerator.java b/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointPropertyConfigurerGenerator.java
index 6e4e236..620e5c0 100644
--- a/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointPropertyConfigurerGenerator.java
+++ b/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointPropertyConfigurerGenerator.java
@@ -20,35 +20,34 @@ import java.io.IOException;
import java.io.Writer;
import java.util.Set;
import javax.annotation.processing.ProcessingEnvironment;
-import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic;
import javax.tools.FileObject;
import javax.tools.JavaFileObject;
import javax.tools.StandardLocation;
-import org.apache.camel.spi.annotations.SubServiceFactory;
import org.apache.camel.tools.apt.helper.IOHelper;
import org.apache.camel.tools.apt.model.EndpointOption;
-import org.apache.camel.tools.apt.model.EndpointPath;
import static org.apache.camel.tools.apt.AnnotationProcessorHelper.dumpExceptionToErrorFile;
public final class EndpointPropertyConfigurerGenerator {
+ // TODO: We can omit the read properties as we only use the writes
+
private EndpointPropertyConfigurerGenerator() {
}
public static void generatePropertyConfigurer(ProcessingEnvironment processingEnv, TypeElement parent,
String pn, String cn, String fqn, String en, String fqen,
- Set<EndpointPath> paths, Set<EndpointOption> options) {
+ Set<EndpointOption> options) {
Writer w = null;
try {
JavaFileObject src = processingEnv.getFiler().createSourceFile(fqn, parent);
w = src.openWriter();
- int size = paths.size() + options.size();
+ int size = options.size();
w.write("/* Generated by org.apache.camel:apt */\n");
w.write("package " + pn + ";\n");
@@ -76,15 +75,6 @@ public final class EndpointPropertyConfigurerGenerator {
w.write(" " + en + " endpoint = (" + en + ") object;\n");
w.write("\n");
- // only include string types as they are the only ones we can use for property placeholders
- for (EndpointPath option : paths) {
- String getOrSet = option.getName();
- getOrSet = Character.toUpperCase(getOrSet.charAt(0)) + getOrSet.substring(1);
- String getterLambda = getterLambda(getOrSet, option.getName(), option.getType());
- String setterLambda = setterLambda(getOrSet, option.getName(), option.getType());
- w.write(" readPlaceholders.put(\"" + option.getName() + "\", " + getterLambda + ");\n");
- w.write(" writePlaceholders.put(\"" + option.getName() + "\", " + setterLambda + ");\n");
- }
for (EndpointOption option : options) {
String getOrSet = option.getName();
getOrSet = Character.toUpperCase(getOrSet.charAt(0)) + getOrSet.substring(1);