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 2020/01/07 09:01:12 UTC

[camel] 05/08: CAMEL-14359: camel-bean - Adding bean scope option.

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

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

commit 2745841d1ecf27e06766adf8716325a33e314138
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Jan 6 20:41:11 2020 +0100

    CAMEL-14359: camel-bean - Adding bean scope option.
---
 .../camel-bean/src/main/docs/bean-component.adoc   |   8 +-
 .../camel-bean/src/main/docs/class-component.adoc  |   8 +-
 .../component/bean/AbstractBeanProcessor.java      |  13 ++-
 .../apache/camel/component/bean/BeanComponent.java |  34 +++---
 .../apache/camel/component/bean/BeanEndpoint.java  |  42 +++----
 .../apache/camel/component/bean/BeanProcessor.java |  12 +-
 .../org/apache/camel/component/bean/BeanScope.java |  27 +++++
 .../apache/camel/processor/BeanSingletonTest.java  |   4 +-
 .../endpoint/dsl/BeanEndpointBuilderFactory.java   | 122 ++++++++++++---------
 .../endpoint/dsl/ClassEndpointBuilderFactory.java  | 122 ++++++++++++---------
 10 files changed, 240 insertions(+), 152 deletions(-)

diff --git a/components/camel-bean/src/main/docs/bean-component.adoc b/components/camel-bean/src/main/docs/bean-component.adoc
index 389a924..d8df9fa 100644
--- a/components/camel-bean/src/main/docs/bean-component.adoc
+++ b/components/camel-bean/src/main/docs/bean-component.adoc
@@ -31,7 +31,7 @@ The Bean component supports 5 options, which are listed below.
 |===
 | Name | Description | Default | Type
 | *cache* (producer) | *Deprecated* Use singleton option instead. | true | Boolean
-| *singleton* (producer) | Whether to use singleton scoped beans. If enabled then the bean is created or looked up once and reused (the bean should be thread-safe). Setting this to false will let Camel create/lookup a new bean instance, per use; which acts as prototype scoped. However beware that if you lookup the bean, then the registry that holds the bean, would return a bean accordingly to its configuration, which can be singleton or prototype scoped. For example if you use Spring, or [...]
+| *scope* (producer) | 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 times while  [...]
 | *basicPropertyBinding* (advanced) | Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
 | *lazyStartProducer* (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 then creating and [...]
 | *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean
@@ -65,12 +65,12 @@ with the following path and query parameters:
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
 | Name | Description | Default | Type
-| *cache* (common) | *Deprecated* Use singleton option instead. |  | Boolean
+| *cache* (common) | *Deprecated* Use scope option instead. |  | Boolean
 | *method* (common) | Sets the name of the method to invoke on the bean |  | String
-| *parameters* (common) | Used for configuring additional properties on the bean |  | Map
-| *singleton* (common) | Whether to use singleton scoped beans. If enabled then the bean is created or looked up once and reused (the bean should be thread-safe). Setting this to false will let Camel create/lookup a new bean instance, per use; which acts as prototype scoped. However beware that if you lookup the bean, then the registry that holds the bean, would return a bean accordingly to its configuration, which can be singleton or prototype scoped. For example if you use Spring, or C [...]
+| *scope* (common) | 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 times while pr [...]
 | *lazyStartProducer* (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 then creating and [...]
 | *basicPropertyBinding* (advanced) | Whether the endpoint should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
+| *parameters* (advanced) | Used for configuring additional properties on the bean |  | Map
 | *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean
 |===
 // endpoint options: END
diff --git a/components/camel-bean/src/main/docs/class-component.adoc b/components/camel-bean/src/main/docs/class-component.adoc
index 0e3fa66..2caeb1e 100644
--- a/components/camel-bean/src/main/docs/class-component.adoc
+++ b/components/camel-bean/src/main/docs/class-component.adoc
@@ -34,7 +34,7 @@ The Class component supports 5 options, which are listed below.
 |===
 | Name | Description | Default | Type
 | *cache* (producer) | *Deprecated* Use singleton option instead. | true | Boolean
-| *singleton* (producer) | Whether to use singleton scoped beans. If enabled then the bean is created or looked up once and reused (the bean should be thread-safe). Setting this to false will let Camel create/lookup a new bean instance, per use; which acts as prototype scoped. However beware that if you lookup the bean, then the registry that holds the bean, would return a bean accordingly to its configuration, which can be singleton or prototype scoped. For example if you use Spring, or [...]
+| *scope* (producer) | 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 times while  [...]
 | *basicPropertyBinding* (advanced) | Whether the component should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
 | *lazyStartProducer* (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 then creating and [...]
 | *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean
@@ -68,12 +68,12 @@ with the following path and query parameters:
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
 | Name | Description | Default | Type
-| *cache* (common) | *Deprecated* Use singleton option instead. |  | Boolean
+| *cache* (common) | *Deprecated* Use scope option instead. |  | Boolean
 | *method* (common) | Sets the name of the method to invoke on the bean |  | String
-| *parameters* (common) | Used for configuring additional properties on the bean |  | Map
-| *singleton* (common) | Whether to use singleton scoped beans. If enabled then the bean is created or looked up once and reused (the bean should be thread-safe). Setting this to false will let Camel create/lookup a new bean instance, per use; which acts as prototype scoped. However beware that if you lookup the bean, then the registry that holds the bean, would return a bean accordingly to its configuration, which can be singleton or prototype scoped. For example if you use Spring, or C [...]
+| *scope* (common) | 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 times while pr [...]
 | *lazyStartProducer* (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 then creating and [...]
 | *basicPropertyBinding* (advanced) | Whether the endpoint should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities | false | boolean
+| *parameters* (advanced) | Used for configuring additional properties on the bean |  | Map
 | *synchronous* (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean
 |===
 // endpoint options: END
diff --git a/components/camel-bean/src/main/java/org/apache/camel/component/bean/AbstractBeanProcessor.java b/components/camel-bean/src/main/java/org/apache/camel/component/bean/AbstractBeanProcessor.java
index 25b8ac7..62deec6 100644
--- a/components/camel-bean/src/main/java/org/apache/camel/component/bean/AbstractBeanProcessor.java
+++ b/components/camel-bean/src/main/java/org/apache/camel/component/bean/AbstractBeanProcessor.java
@@ -35,7 +35,7 @@ public abstract class AbstractBeanProcessor extends AsyncProcessorSupport {
     private transient Processor processor;
     private transient boolean lookupProcessorDone;
     private final Object lock = new Object();
-    private Boolean singleton;
+    private BeanScope scope;
     private String method;
     private boolean shorthandMethod;
 
@@ -88,7 +88,8 @@ public abstract class AbstractBeanProcessor extends AsyncProcessorSupport {
             Processor target = getProcessor();
             if (target == null) {
                 // only attempt to lookup the processor once or nearly once
-                boolean allowCache = singleton == null || singleton; // allow cache by default
+                // allow cache by default or if the scope is singleton
+                boolean allowCache = scope == null || scope == BeanScope.Singleton;
                 if (allowCache) {
                     if (!lookupProcessorDone) {
                         synchronized (lock) {
@@ -167,12 +168,12 @@ public abstract class AbstractBeanProcessor extends AsyncProcessorSupport {
         return method;
     }
 
-    public Boolean getSingleton() {
-        return singleton;
+    public BeanScope getScope() {
+        return scope;
     }
 
-    public void setSingleton(Boolean singleton) {
-        this.singleton = singleton;
+    public void setScope(BeanScope scope) {
+        this.scope = scope;
     }
 
     /**
diff --git a/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanComponent.java b/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanComponent.java
index 0d0a403..9bd470e 100644
--- a/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanComponent.java
+++ b/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanComponent.java
@@ -39,12 +39,16 @@ public class BeanComponent extends DefaultComponent {
     @Deprecated
     @Metadata(defaultValue = "true", description = "Use singleton option instead.")
     private Boolean cache;
-    @Metadata(defaultValue = "true", description = "Whether to use singleton scoped beans. If enabled then the bean"
-            + " is created or looked up once and reused (the bean should be thread-safe). Setting this to false will let Camel create/lookup"
-            + " a new bean instance, per use; which acts as prototype scoped. However beware that if you lookup the bean, then the registry that holds the bean, would return "
-            + " a bean accordingly to its configuration, which can be singleton or prototype scoped. For example if you use Spring, or CDI, which"
-            + " has their own settings for setting bean scopes.")
-    private Boolean singleton = Boolean.TRUE;
+    @Metadata(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 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 times while processing the request."
+            + " The bean should not be thread-safe as the instance is only called from the same request.  "
+            + " When using delegate scope, then the bean will be looked up or created per call. However in case of lookup then this is delegated "
+            + " to the bean registry such as Spring or CDI (if in use), which depends on their configuration can act as either singleton or prototype scope."
+            + " so when using delegate then this depends on the delegated registry.")
+    private BeanScope scope = BeanScope.Singleton;
 
     public BeanComponent() {
     }
@@ -58,7 +62,7 @@ public class BeanComponent extends DefaultComponent {
         if (cache != null) {
             endpoint.setCache(cache);
         }
-        endpoint.setSingleton(singleton);
+        endpoint.setScope(scope);
         setProperties(endpoint, parameters);
 
         // the bean.xxx options is for the bean
@@ -86,19 +90,23 @@ public class BeanComponent extends DefaultComponent {
 
     @Deprecated
     public Boolean getCache() {
-        return singleton;
+        return scope == BeanScope.Singleton;
     }
 
     @Deprecated
     public void setCache(Boolean cache) {
-        this.singleton = cache;
+        if (cache) {
+            scope = BeanScope.Singleton;
+        } else {
+            scope = BeanScope.Delegate;
+        }
     }
 
-    public Boolean getSingleton() {
-        return singleton;
+    public BeanScope getScope() {
+        return scope;
     }
 
-    public void setSingleton(Boolean singleton) {
-        this.singleton = singleton;
+    public void setScope(BeanScope scope) {
+        this.scope = scope;
     }
 }
diff --git a/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanEndpoint.java b/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanEndpoint.java
index 0e3b954..1c6dd74 100644
--- a/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanEndpoint.java
+++ b/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanEndpoint.java
@@ -41,15 +41,19 @@ public class BeanEndpoint extends DefaultEndpoint {
     @UriParam(label = "common", description = "Sets the name of the method to invoke on the bean")
     private String method;
     @Deprecated
-    @UriParam(label = "common", description = "Use singleton option instead.")
+    @UriParam(label = "common", description = "Use scope option instead.")
     private Boolean cache;
-    @UriParam(label = "common", defaultValue = "true", description = "Whether to use singleton scoped beans. If enabled then the bean"
-            + " is created or looked up once and reused (the bean should be thread-safe). Setting this to false will let Camel create/lookup"
-            + " a new bean instance, per use; which acts as prototype scoped. However beware that if you lookup the bean, then the registry that holds the bean, would return "
-            + " a bean accordingly to its configuration, which can be singleton or prototype scoped. For example if you use Spring, or CDI, which"
-            + " has their own settings for setting bean scopes.")
-    private Boolean singleton = Boolean.TRUE;
-    @UriParam(prefix = "bean.", label = "common", description = "Used for configuring additional properties on the bean", multiValue = true)
+    @UriParam(label = "common", 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 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 times while processing the request."
+            + " The bean should not be thread-safe as the instance is only called from the same request.  "
+            + " When using delegate scope, then the bean will be looked up or created per call. However in case of lookup then this is delegated "
+            + " to the bean registry such as Spring or CDI (if in use), which depends on their configuration can act as either singleton or prototype scope."
+            + " so when using delegate then this depends on the delegated registry.")
+    private BeanScope scope = BeanScope.Singleton;
+    @UriParam(prefix = "bean.", label = "advanced", description = "Used for configuring additional properties on the bean", multiValue = true)
     private Map<String, Object> parameters;
 
     public BeanEndpoint() {
@@ -100,7 +104,7 @@ public class BeanEndpoint extends DefaultEndpoint {
             if (method != null) {
                 processor.setMethod(method);
             }
-            processor.setSingleton(singleton);
+            processor.setScope(scope);
             if (parameters != null) {
                 setProperties(processor, parameters);
             }
@@ -131,24 +135,24 @@ public class BeanEndpoint extends DefaultEndpoint {
 
     @Deprecated
     public Boolean getCache() {
-        return getSingleton();
+        return scope == BeanScope.Singleton;
     }
 
     @Deprecated
     public void setCache(Boolean cache) {
-        setSingleton(cache);
-    }
-
-    public boolean isSingleton() {
-        return singleton != null ? singleton : false;
+        if (cache) {
+            scope = BeanScope.Singleton;
+        } else {
+            scope = BeanScope.Delegate;
+        }
     }
 
-    public Boolean getSingleton() {
-        return singleton;
+    public BeanScope getScope() {
+        return scope;
     }
 
-    public void setSingleton(Boolean singleton) {
-        this.singleton = singleton;
+    public void setScope(BeanScope scope) {
+        this.scope = scope;
     }
 
     public String getMethod() {
diff --git a/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanProcessor.java b/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
index b9ad238..72342e8 100644
--- a/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
+++ b/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanProcessor.java
@@ -76,16 +76,16 @@ public class BeanProcessor extends ServiceSupport implements AsyncProcessor {
         return delegate.getMethod();
     }
 
-    public Boolean getSingleton() {
-        return delegate.getSingleton();
+    public void setMethod(String method) {
+        delegate.setMethod(method);
     }
 
-    public void setSingleton(Boolean singleton) {
-        delegate.setSingleton(singleton);
+    public BeanScope getScope() {
+        return delegate.getScope();
     }
 
-    public void setMethod(String method) {
-        delegate.setMethod(method);
+    public void setScope(BeanScope scope) {
+        delegate.setScope(scope);
     }
 
     public boolean isShorthandMethod() {
diff --git a/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanScope.java b/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanScope.java
new file mode 100644
index 0000000..9012a55
--- /dev/null
+++ b/components/camel-bean/src/main/java/org/apache/camel/component/bean/BeanScope.java
@@ -0,0 +1,27 @@
+/*
+ * 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.bean;
+
+/**
+ * Bean scopes.
+ */
+public enum BeanScope {
+
+    Singleton,
+    Delegate,
+    Request;
+}
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/BeanSingletonTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/BeanSingletonTest.java
index b5104be..8f2c857 100644
--- a/core/camel-core/src/test/java/org/apache/camel/processor/BeanSingletonTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/processor/BeanSingletonTest.java
@@ -36,8 +36,8 @@ public class BeanSingletonTest extends ContextTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() {
-                from("direct:noCache").to("bean:something?singleton=false");
-                from("direct:cached").to("bean:something?singleton=true");
+                from("direct:noCache").to("bean:something?scope=Delegate");
+                from("direct:cached").to("bean:something?scope=Singleton");
             }
         };
     }
diff --git a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/BeanEndpointBuilderFactory.java b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/BeanEndpointBuilderFactory.java
index 471c756..0930ec3 100644
--- a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/BeanEndpointBuilderFactory.java
+++ b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/BeanEndpointBuilderFactory.java
@@ -39,7 +39,7 @@ public interface BeanEndpointBuilderFactory {
             return (AdvancedBeanEndpointBuilder) this;
         }
         /**
-         * Use singleton option instead.
+         * Use scope option instead.
          * 
          * The option is a: <code>java.lang.Boolean</code> type.
          * 
@@ -51,7 +51,7 @@ public interface BeanEndpointBuilderFactory {
             return this;
         }
         /**
-         * Use singleton option instead.
+         * Use scope option instead.
          * 
          * The option will be converted to a <code>java.lang.Boolean</code>
          * type.
@@ -75,65 +75,53 @@ public interface BeanEndpointBuilderFactory {
             return this;
         }
         /**
-         * Used for configuring additional properties on the bean.
+         * 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 times while
+         * processing the request. The bean should not be thread-safe as the
+         * instance is only called from the same request. When using delegate
+         * scope, then the bean will be looked up or created per call. However
+         * in case of lookup then this is delegated to the bean registry such as
+         * Spring or CDI (if in use), which depends on their configuration can
+         * act as either singleton or prototype scope. so when using delegate
+         * then this depends on the delegated registry.
          * 
-         * The option is a: <code>java.util.Map&lt;java.lang.String,
-         * java.lang.Object&gt;</code> type.
+         * The option is a:
+         * <code>org.apache.camel.component.bean.BeanScope</code> type.
          * 
          * Group: common
          */
-        default BeanEndpointBuilder parameters(Map<String, Object> parameters) {
-            doSetProperty("parameters", parameters);
+        default BeanEndpointBuilder scope(BeanScope scope) {
+            doSetProperty("scope", scope);
             return this;
         }
         /**
-         * Used for configuring additional properties on the bean.
+         * 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 times while
+         * processing the request. The bean should not be thread-safe as the
+         * instance is only called from the same request. When using delegate
+         * scope, then the bean will be looked up or created per call. However
+         * in case of lookup then this is delegated to the bean registry such as
+         * Spring or CDI (if in use), which depends on their configuration can
+         * act as either singleton or prototype scope. so when using delegate
+         * then this depends on the delegated registry.
          * 
          * The option will be converted to a
-         * <code>java.util.Map&lt;java.lang.String, java.lang.Object&gt;</code>
-         * type.
-         * 
-         * Group: common
-         */
-        default BeanEndpointBuilder parameters(String parameters) {
-            doSetProperty("parameters", parameters);
-            return this;
-        }
-        /**
-         * Whether to use singleton scoped beans. If enabled then the bean is
-         * created or looked up once and reused (the bean should be
-         * thread-safe). Setting this to false will let Camel create/lookup a
-         * new bean instance, per use; which acts as prototype scoped. However
-         * beware that if you lookup the bean, then the registry that holds the
-         * bean, would return a bean accordingly to its configuration, which can
-         * be singleton or prototype scoped. For example if you use Spring, or
-         * CDI, which has their own settings for setting bean scopes.
-         * 
-         * The option is a: <code>java.lang.Boolean</code> type.
+         * <code>org.apache.camel.component.bean.BeanScope</code> type.
          * 
          * Group: common
          */
-        default BeanEndpointBuilder singleton(Boolean singleton) {
-            doSetProperty("singleton", singleton);
-            return this;
-        }
-        /**
-         * Whether to use singleton scoped beans. If enabled then the bean is
-         * created or looked up once and reused (the bean should be
-         * thread-safe). Setting this to false will let Camel create/lookup a
-         * new bean instance, per use; which acts as prototype scoped. However
-         * beware that if you lookup the bean, then the registry that holds the
-         * bean, would return a bean accordingly to its configuration, which can
-         * be singleton or prototype scoped. For example if you use Spring, or
-         * CDI, which has their own settings for setting bean scopes.
-         * 
-         * The option will be converted to a <code>java.lang.Boolean</code>
-         * type.
-         * 
-         * Group: common
-         */
-        default BeanEndpointBuilder singleton(String singleton) {
-            doSetProperty("singleton", singleton);
+        default BeanEndpointBuilder scope(String scope) {
+            doSetProperty("scope", scope);
             return this;
         }
         /**
@@ -212,6 +200,32 @@ public interface BeanEndpointBuilderFactory {
             return this;
         }
         /**
+         * Used for configuring additional properties on the bean.
+         * 
+         * The option is a: <code>java.util.Map&lt;java.lang.String,
+         * java.lang.Object&gt;</code> type.
+         * 
+         * Group: advanced
+         */
+        default AdvancedBeanEndpointBuilder parameters(
+                Map<String, Object> parameters) {
+            doSetProperty("parameters", parameters);
+            return this;
+        }
+        /**
+         * Used for configuring additional properties on the bean.
+         * 
+         * The option will be converted to a
+         * <code>java.util.Map&lt;java.lang.String, java.lang.Object&gt;</code>
+         * type.
+         * 
+         * Group: advanced
+         */
+        default AdvancedBeanEndpointBuilder parameters(String parameters) {
+            doSetProperty("parameters", parameters);
+            return this;
+        }
+        /**
          * Sets whether synchronous processing should be strictly used, or Camel
          * is allowed to use asynchronous processing (if supported).
          * 
@@ -236,6 +250,16 @@ public interface BeanEndpointBuilderFactory {
             return this;
         }
     }
+
+    /**
+     * Proxy enum for <code>org.apache.camel.component.bean.BeanScope</code>
+     * enum.
+     */
+    enum BeanScope {
+        Singleton,
+        Delegate,
+        Request;
+    }
     /**
      * Bean (camel-bean)
      * The bean component is for invoking Java beans from Camel.
diff --git a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/ClassEndpointBuilderFactory.java b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/ClassEndpointBuilderFactory.java
index 2718f10..125d4d7 100644
--- a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/ClassEndpointBuilderFactory.java
+++ b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/ClassEndpointBuilderFactory.java
@@ -39,7 +39,7 @@ public interface ClassEndpointBuilderFactory {
             return (AdvancedClassEndpointBuilder) this;
         }
         /**
-         * Use singleton option instead.
+         * Use scope option instead.
          * 
          * The option is a: <code>java.lang.Boolean</code> type.
          * 
@@ -51,7 +51,7 @@ public interface ClassEndpointBuilderFactory {
             return this;
         }
         /**
-         * Use singleton option instead.
+         * Use scope option instead.
          * 
          * The option will be converted to a <code>java.lang.Boolean</code>
          * type.
@@ -75,65 +75,53 @@ public interface ClassEndpointBuilderFactory {
             return this;
         }
         /**
-         * Used for configuring additional properties on the bean.
+         * 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 times while
+         * processing the request. The bean should not be thread-safe as the
+         * instance is only called from the same request. When using delegate
+         * scope, then the bean will be looked up or created per call. However
+         * in case of lookup then this is delegated to the bean registry such as
+         * Spring or CDI (if in use), which depends on their configuration can
+         * act as either singleton or prototype scope. so when using delegate
+         * then this depends on the delegated registry.
          * 
-         * The option is a: <code>java.util.Map&lt;java.lang.String,
-         * java.lang.Object&gt;</code> type.
+         * The option is a:
+         * <code>org.apache.camel.component.bean.BeanScope</code> type.
          * 
          * Group: common
          */
-        default ClassEndpointBuilder parameters(Map<String, Object> parameters) {
-            doSetProperty("parameters", parameters);
+        default ClassEndpointBuilder scope(BeanScope scope) {
+            doSetProperty("scope", scope);
             return this;
         }
         /**
-         * Used for configuring additional properties on the bean.
+         * 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 times while
+         * processing the request. The bean should not be thread-safe as the
+         * instance is only called from the same request. When using delegate
+         * scope, then the bean will be looked up or created per call. However
+         * in case of lookup then this is delegated to the bean registry such as
+         * Spring or CDI (if in use), which depends on their configuration can
+         * act as either singleton or prototype scope. so when using delegate
+         * then this depends on the delegated registry.
          * 
          * The option will be converted to a
-         * <code>java.util.Map&lt;java.lang.String, java.lang.Object&gt;</code>
-         * type.
-         * 
-         * Group: common
-         */
-        default ClassEndpointBuilder parameters(String parameters) {
-            doSetProperty("parameters", parameters);
-            return this;
-        }
-        /**
-         * Whether to use singleton scoped beans. If enabled then the bean is
-         * created or looked up once and reused (the bean should be
-         * thread-safe). Setting this to false will let Camel create/lookup a
-         * new bean instance, per use; which acts as prototype scoped. However
-         * beware that if you lookup the bean, then the registry that holds the
-         * bean, would return a bean accordingly to its configuration, which can
-         * be singleton or prototype scoped. For example if you use Spring, or
-         * CDI, which has their own settings for setting bean scopes.
-         * 
-         * The option is a: <code>java.lang.Boolean</code> type.
+         * <code>org.apache.camel.component.bean.BeanScope</code> type.
          * 
          * Group: common
          */
-        default ClassEndpointBuilder singleton(Boolean singleton) {
-            doSetProperty("singleton", singleton);
-            return this;
-        }
-        /**
-         * Whether to use singleton scoped beans. If enabled then the bean is
-         * created or looked up once and reused (the bean should be
-         * thread-safe). Setting this to false will let Camel create/lookup a
-         * new bean instance, per use; which acts as prototype scoped. However
-         * beware that if you lookup the bean, then the registry that holds the
-         * bean, would return a bean accordingly to its configuration, which can
-         * be singleton or prototype scoped. For example if you use Spring, or
-         * CDI, which has their own settings for setting bean scopes.
-         * 
-         * The option will be converted to a <code>java.lang.Boolean</code>
-         * type.
-         * 
-         * Group: common
-         */
-        default ClassEndpointBuilder singleton(String singleton) {
-            doSetProperty("singleton", singleton);
+        default ClassEndpointBuilder scope(String scope) {
+            doSetProperty("scope", scope);
             return this;
         }
         /**
@@ -212,6 +200,32 @@ public interface ClassEndpointBuilderFactory {
             return this;
         }
         /**
+         * Used for configuring additional properties on the bean.
+         * 
+         * The option is a: <code>java.util.Map&lt;java.lang.String,
+         * java.lang.Object&gt;</code> type.
+         * 
+         * Group: advanced
+         */
+        default AdvancedClassEndpointBuilder parameters(
+                Map<String, Object> parameters) {
+            doSetProperty("parameters", parameters);
+            return this;
+        }
+        /**
+         * Used for configuring additional properties on the bean.
+         * 
+         * The option will be converted to a
+         * <code>java.util.Map&lt;java.lang.String, java.lang.Object&gt;</code>
+         * type.
+         * 
+         * Group: advanced
+         */
+        default AdvancedClassEndpointBuilder parameters(String parameters) {
+            doSetProperty("parameters", parameters);
+            return this;
+        }
+        /**
          * Sets whether synchronous processing should be strictly used, or Camel
          * is allowed to use asynchronous processing (if supported).
          * 
@@ -236,6 +250,16 @@ public interface ClassEndpointBuilderFactory {
             return this;
         }
     }
+
+    /**
+     * Proxy enum for <code>org.apache.camel.component.bean.BeanScope</code>
+     * enum.
+     */
+    enum BeanScope {
+        Singleton,
+        Delegate,
+        Request;
+    }
     /**
      * Class (camel-bean)
      * The Class component is for invoking Java classes (Java beans) from Camel.