This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new 38e3ebb CAMEL-16733: Polished and update docs 38e3ebb is described below commit 38e3ebb8a2d1237b79e738a110e2952221566b51 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Mon Jun 21 10:29:52 2021 +0200 CAMEL-16733: Polished and update docs --- .../apache/camel/catalog/docs/bean-language.adoc | 4 ++-- .../org/apache/camel/language/bean/bean.json | 4 ++-- .../camel-bean/src/main/docs/bean-language.adoc | 4 ++-- .../component/bean/ConstantTypeBeanHolder.java | 26 +++++++++++----------- .../org/apache/camel/model/language/method.json | 2 +- .../org/apache/camel/builder/ExpressionClause.java | 12 ++++++++++ .../camel/builder/ExpressionClauseSupport.java | 12 ++++++++++ .../camel/model/language/MethodCallExpression.java | 3 +++ .../modules/languages/pages/bean-language.adoc | 4 ++-- .../ROOT/pages/camel-3x-upgrade-guide-3_11.adoc | 6 +++++ 10 files changed, 55 insertions(+), 22 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/bean-language.adoc b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/bean-language.adoc index b806a0b..8df7e6f 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/bean-language.adoc +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/bean-language.adoc @@ -34,9 +34,9 @@ The Bean method language supports 5 options, which are listed below. [width="100%",cols="2,1m,1m,6",options="header"] |=== | Name | Default | Java Type | Description -| ref | | String | Reference to bean to lookup in the registry +| ref | | String | Reference to an existing bean (bean id) to lookup in the registry | method | | String | Name of method to call -| beanType | | String | Class name of the bean to use +| beanType | | String | Class name (fully qualified) of the bean to use Will lookup in registry and if there is a single instance of the same type, then the existing bean is used, otherwise a new bean is created (requires a default no-arg constructor). | scope | Singleton | String | Scope of bean. When using singleton scope (default) the bean is created or looked up only once and reused for the lifetime of the endpoint. The bean should be thread-safe in case concurrent threads is calling the bean at the same time. When using request scope the bean is created or looked up once per request (exchange). This can be used if you want to store state on a bean while processing a request and you want to call the same bean instance multiple time [...] | trim | true | Boolean | Whether to trim the value to remove leading and trailing whitespaces and line breaks |=== diff --git a/components/camel-bean/src/generated/resources/org/apache/camel/language/bean/bean.json b/components/camel-bean/src/generated/resources/org/apache/camel/language/bean/bean.json index 8ce1dce..594c1b0 100644 --- a/components/camel-bean/src/generated/resources/org/apache/camel/language/bean/bean.json +++ b/components/camel-bean/src/generated/resources/org/apache/camel/language/bean/bean.json @@ -16,9 +16,9 @@ "modelJavaType": "org.apache.camel.model.language.MethodCallExpression" }, "properties": { - "ref": { "kind": "attribute", "displayName": "Ref", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Reference to bean to lookup in the registry" }, + "ref": { "kind": "attribute", "displayName": "Ref", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Reference to an existing bean (bean id) to lookup in the registry" }, "method": { "kind": "attribute", "displayName": "Method", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of method to call" }, - "beanType": { "kind": "attribute", "displayName": "Bean Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Class name of the bean to use" }, + "beanType": { "kind": "attribute", "displayName": "Bean Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Class name (fully qualified) of the bean to use Will lookup in registry and if there is a single instance of the same type, then the existing bean is used, otherwise a new bean is created (requires a default no-arg constructor)." }, "scope": { "kind": "attribute", "displayName": "Scope", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "Prototype", "Request", "Singleton" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "Singleton", "description": "Scope of bean. When using singleton scope (default) the bean is created or looked up only once and reused for the lifetime of the endpoint. The bean should be thread-safe in case concurrent threads is calling the [...] "trim": { "kind": "attribute", "displayName": "Trim", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to trim the value to remove leading and trailing whitespaces and line breaks" }, "id": { "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the id of this node" } diff --git a/components/camel-bean/src/main/docs/bean-language.adoc b/components/camel-bean/src/main/docs/bean-language.adoc index b806a0b..8df7e6f 100644 --- a/components/camel-bean/src/main/docs/bean-language.adoc +++ b/components/camel-bean/src/main/docs/bean-language.adoc @@ -34,9 +34,9 @@ The Bean method language supports 5 options, which are listed below. [width="100%",cols="2,1m,1m,6",options="header"] |=== | Name | Default | Java Type | Description -| ref | | String | Reference to bean to lookup in the registry +| ref | | String | Reference to an existing bean (bean id) to lookup in the registry | method | | String | Name of method to call -| beanType | | String | Class name of the bean to use +| beanType | | String | Class name (fully qualified) of the bean to use Will lookup in registry and if there is a single instance of the same type, then the existing bean is used, otherwise a new bean is created (requires a default no-arg constructor). | scope | Singleton | String | Scope of bean. When using singleton scope (default) the bean is created or looked up only once and reused for the lifetime of the endpoint. The bean should be thread-safe in case concurrent threads is calling the bean at the same time. When using request scope the bean is created or looked up once per request (exchange). This can be used if you want to store state on a bean while processing a request and you want to call the same bean instance multiple time [...] | trim | true | Boolean | Whether to trim the value to remove leading and trailing whitespaces and line breaks |=== diff --git a/components/camel-bean/src/main/java/org/apache/camel/component/bean/ConstantTypeBeanHolder.java b/components/camel-bean/src/main/java/org/apache/camel/component/bean/ConstantTypeBeanHolder.java index 6257325..01d2b18 100644 --- a/components/camel-bean/src/main/java/org/apache/camel/component/bean/ConstantTypeBeanHolder.java +++ b/components/camel-bean/src/main/java/org/apache/camel/component/bean/ConstantTypeBeanHolder.java @@ -17,11 +17,11 @@ package org.apache.camel.component.bean; import java.util.Map; -import java.util.Set; import org.apache.camel.CamelContext; import org.apache.camel.Exchange; import org.apache.camel.Processor; +import org.apache.camel.support.CamelContextHelper; import org.apache.camel.support.PropertyBindingSupport; import org.apache.camel.util.ObjectHelper; @@ -29,6 +29,7 @@ import org.apache.camel.util.ObjectHelper; * A constant (singleton) bean implementation of {@link org.apache.camel.component.bean.BeanTypeHolder} */ public class ConstantTypeBeanHolder implements BeanTypeHolder { + private final CamelContext camelContext; private final Class<?> type; private final BeanInfo beanInfo; private Map<String, Object> options; @@ -44,6 +45,7 @@ public class ConstantTypeBeanHolder implements BeanTypeHolder { this.type = type; this.beanInfo = beanInfo; + this.camelContext = beanInfo.getCamelContext(); } @Override @@ -80,26 +82,24 @@ public class ConstantTypeBeanHolder implements BeanTypeHolder { @Override public Object getBean(Exchange exchange) { - // try to get the bean from registry first if there is a single candidate for the type. - Set<?> beans = beanInfo.getCamelContext().getRegistry().findByType(type); - if (beans.size() == 1) { - return beans.iterator().next(); - } - // only create a bean if we have a default no-arg constructor and not present in the registry - if (beanInfo.hasPublicNoArgConstructors()) { - Object bean = getBeanInfo().getCamelContext().getInjector().newInstance(type, false); + // try to get the bean from registry first if there is a single candidate for the type + Object answer = CamelContextHelper.findByType(camelContext, type); + + // if not then create a new bean instance from the type + if (answer == null && beanInfo.hasPublicNoArgConstructors()) { + // only create a bean if we have a default no-arg constructor and not present in the registry + answer = getBeanInfo().getCamelContext().getInjector().newInstance(type, false); if (options != null && !options.isEmpty()) { PropertyBindingSupport.build() .withRemoveParameters(false) .withCamelContext(getBeanInfo().getCamelContext()) .withProperties(options) - .withTarget(bean) + .withTarget(answer) .bind(); } - return bean; - } else { - return null; } + + return answer; } @Override diff --git a/core/camel-core-model/src/generated/resources/org/apache/camel/model/language/method.json b/core/camel-core-model/src/generated/resources/org/apache/camel/model/language/method.json index edf670e..da7f3db 100644 --- a/core/camel-core-model/src/generated/resources/org/apache/camel/model/language/method.json +++ b/core/camel-core-model/src/generated/resources/org/apache/camel/model/language/method.json @@ -14,7 +14,7 @@ "properties": { "ref": { "kind": "attribute", "displayName": "Ref", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Reference to an existing bean (bean id) to lookup in the registry" }, "method": { "kind": "attribute", "displayName": "Method", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of method to call" }, - "beanType": { "kind": "attribute", "displayName": "Bean Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Class name (fully qualified) of the bean to use" }, + "beanType": { "kind": "attribute", "displayName": "Bean Type", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Class name (fully qualified) of the bean to use Will lookup in registry and if there is a single instance of the same type, then the existing bean is used, otherwise a new bean is created (requires a default no-arg constructor)." }, "scope": { "kind": "attribute", "displayName": "Scope", "required": false, "type": "enum", "javaType": "java.lang.String", "enum": [ "Prototype", "Request", "Singleton" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "Singleton", "description": "Scope of bean. When using singleton scope (default) the bean is created or looked up only once and reused for the lifetime of the endpoint. The bean should be thread-safe in case concurrent threads is calling the [...] "trim": { "kind": "attribute", "displayName": "Trim", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether to trim the value to remove leading and trailing whitespaces and line breaks" }, "id": { "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the id of this node" } diff --git a/core/camel-core-model/src/main/java/org/apache/camel/builder/ExpressionClause.java b/core/camel-core-model/src/main/java/org/apache/camel/builder/ExpressionClause.java index d90e568..f0f1f75 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/builder/ExpressionClause.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/builder/ExpressionClause.java @@ -227,6 +227,9 @@ public class ExpressionClause<T> implements Expression, Predicate { * Evaluates an expression using the <a href="http://camel.apache.org/bean-language.html">bean language</a> which * basically means the bean is invoked to determine the expression value. * + * Will lookup in registry and if there is a single instance of the same type, then the existing bean is used, + * otherwise a new bean is created (requires a default no-arg constructor). + * * @param beanType the Class of the bean which we want to invoke * @return the builder to continue processing the DSL */ @@ -287,6 +290,9 @@ public class ExpressionClause<T> implements Expression, Predicate { * Evaluates an expression using the <a href="http://camel.apache.org/bean-language.html">bean language</a> which * basically means the bean is invoked to determine the expression value. * + * Will lookup in registry and if there is a single instance of the same type, then the existing bean is used, + * otherwise a new bean is created (requires a default no-arg constructor). + * * @param beanType the Class of the bean which we want to invoke * @param method the name of the method to invoke on the bean * @return the builder to continue processing the DSL @@ -299,6 +305,9 @@ public class ExpressionClause<T> implements Expression, Predicate { * Evaluates an expression using the <a href="http://camel.apache.org/bean-language.html">bean language</a> which * basically means the bean is invoked to determine the expression value. * + * Will lookup in registry and if there is a single instance of the same type, then the existing bean is used, + * otherwise a new bean is created (requires a default no-arg constructor). + * * @param beanType the Class of the bean which we want to invoke * @param scope the scope of the bean * @return the builder to continue processing the DSL @@ -311,6 +320,9 @@ public class ExpressionClause<T> implements Expression, Predicate { * Evaluates an expression using the <a href="http://camel.apache.org/bean-language.html">bean language</a> which * basically means the bean is invoked to determine the expression value. * + * Will lookup in registry and if there is a single instance of the same type, then the existing bean is used, + * otherwise a new bean is created (requires a default no-arg constructor). + * * @param beanType the Class of the bean which we want to invoke * @param method the name of the method to invoke on the bean * @param scope the scope of the bean diff --git a/core/camel-core-model/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java b/core/camel-core-model/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java index 7ac901a..3eadd5b 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/builder/ExpressionClauseSupport.java @@ -201,6 +201,9 @@ public class ExpressionClauseSupport<T> implements ExpressionFactoryAware, Predi * Evaluates an expression using the <a href="http://camel.apache.org/bean-language.html>bean language</a> which * basically means the bean is invoked to determine the expression value. * + * Will lookup in registry and if there is a single instance of the same type, then the existing bean is used, + * otherwise a new bean is created (requires a default no-arg constructor). + * * @param beanType the Class of the bean which we want to invoke * @return the builder to continue processing the DSL */ @@ -265,6 +268,9 @@ public class ExpressionClauseSupport<T> implements ExpressionFactoryAware, Predi * Evaluates an expression using the <a href="http://camel.apache.org/bean-language.html>bean language</a> which * basically means the bean is invoked to determine the expression value. * + * Will lookup in registry and if there is a single instance of the same type, then the existing bean is used, + * otherwise a new bean is created (requires a default no-arg constructor). + * * @param beanType the Class of the bean which we want to invoke * @param method the name of the method to invoke on the bean * @return the builder to continue processing the DSL @@ -277,6 +283,9 @@ public class ExpressionClauseSupport<T> implements ExpressionFactoryAware, Predi * Evaluates an expression using the <a href="http://camel.apache.org/bean-language.html>bean language</a> which * basically means the bean is invoked to determine the expression value. * + * Will lookup in registry and if there is a single instance of the same type, then the existing bean is used, + * otherwise a new bean is created (requires a default no-arg constructor). + * * @param beanType the Class of the bean which we want to invoke * @param scope the scope of the bean * @return the builder to continue processing the DSL @@ -291,6 +300,9 @@ public class ExpressionClauseSupport<T> implements ExpressionFactoryAware, Predi * Evaluates an expression using the <a href="http://camel.apache.org/bean-language.html>bean language</a> which * basically means the bean is invoked to determine the expression value. * + * Will lookup in registry and if there is a single instance of the same type, then the existing bean is used, + * otherwise a new bean is created (requires a default no-arg constructor). + * * @param beanType the Class of the bean which we want to invoke * @param method the name of the method to invoke on the bean * @param scope the scope of the bean diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/language/MethodCallExpression.java b/core/camel-core-model/src/main/java/org/apache/camel/model/language/MethodCallExpression.java index 11ebf37..5ce235a 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/language/MethodCallExpression.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/language/MethodCallExpression.java @@ -128,6 +128,9 @@ public class MethodCallExpression extends ExpressionDefinition { /** * Class name (fully qualified) of the bean to use + * + * Will lookup in registry and if there is a single instance of the same type, then the existing bean is used, + * otherwise a new bean is created (requires a default no-arg constructor). */ public void setBeanTypeName(String beanTypeName) { this.beanTypeName = beanTypeName; diff --git a/docs/components/modules/languages/pages/bean-language.adoc b/docs/components/modules/languages/pages/bean-language.adoc index 2d6438a..97a4ebc 100644 --- a/docs/components/modules/languages/pages/bean-language.adoc +++ b/docs/components/modules/languages/pages/bean-language.adoc @@ -36,9 +36,9 @@ The Bean method language supports 5 options, which are listed below. [width="100%",cols="2,1m,1m,6",options="header"] |=== | Name | Default | Java Type | Description -| ref | | String | Reference to bean to lookup in the registry +| ref | | String | Reference to an existing bean (bean id) to lookup in the registry | method | | String | Name of method to call -| beanType | | String | Class name of the bean to use +| beanType | | String | Class name (fully qualified) of the bean to use Will lookup in registry and if there is a single instance of the same type, then the existing bean is used, otherwise a new bean is created (requires a default no-arg constructor). | scope | Singleton | String | Scope of bean. When using singleton scope (default) the bean is created or looked up only once and reused for the lifetime of the endpoint. The bean should be thread-safe in case concurrent threads is calling the bean at the same time. When using request scope the bean is created or looked up once per request (exchange). This can be used if you want to store state on a bean while processing a request and you want to call the same bean instance multiple time [...] | trim | true | Boolean | Whether to trim the value to remove leading and trailing whitespaces and line breaks |=== diff --git a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_11.adoc b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_11.adoc index 7c046bd..9cd3c43 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_11.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_11.adoc @@ -6,6 +6,12 @@ from both 3.0 to 3.1 and 3.1 to 3.2. == Upgrading Camel 3.10 to 3.11 +=== Bean Language + +When using `beanType` (full qualified class name) with the bean language, +then the bean language will *now* lookup in registry and if there is a single instance of the same type, then the existing bean is used. +If not then a new bean is created (same behavior as before). + === Aggregate EIP The aggregate EIP will now always use a worker thread pool for processing outgoing messages.