This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 4e175db CAMEL-16169: CamelContext.addComponent should auto start
component if context is already started.
4e175db is described below
commit 4e175db4d722beed47aebbffc2a581098961a608
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Mar 18 10:46:22 2021 +0100
CAMEL-16169: CamelContext.addComponent should auto start component if
context is already started.
---
core/camel-api/src/main/java/org/apache/camel/CamelContext.java | 2 ++
.../java/org/apache/camel/impl/engine/AbstractCamelContext.java | 8 +++++++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/core/camel-api/src/main/java/org/apache/camel/CamelContext.java
b/core/camel-api/src/main/java/org/apache/camel/CamelContext.java
index bbc1863..38df764f 100644
--- a/core/camel-api/src/main/java/org/apache/camel/CamelContext.java
+++ b/core/camel-api/src/main/java/org/apache/camel/CamelContext.java
@@ -323,6 +323,8 @@ public interface CamelContext extends
CamelContextLifecycle, RuntimeConfiguratio
/**
* Adds a component to the context.
*
+ * Notice the component will be auto-started if Camel is already started.
+ *
* @param componentName the name the component is registered as
* @param component the component
*/
diff --git
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index d86be48..079045f 100644
---
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -550,7 +550,13 @@ public abstract class AbstractCamelContext extends
BaseService
public void addComponent(String componentName, final Component component) {
ObjectHelper.notNull(component, "component");
component.setCamelContext(getCamelContextReference());
- ServiceHelper.initService(component);
+ if (isStarted()) {
+ // start component if context is already started (camel will start
components when it starts)
+ ServiceHelper.startService(component);
+ } else {
+ // otherwise init the component
+ ServiceHelper.initService(component);
+ }
Component oldValue = components.putIfAbsent(componentName, component);
if (oldValue != null) {
throw new IllegalArgumentException("Cannot add component as its
already previously added: " + componentName);