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 2021/08/06 06:53:10 UTC
[camel] branch camel-3.11.x updated: CAMEL-16850: camel-main -
Should only clear its internal main configuration if in lightweight mode.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-3.11.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.11.x by this push:
new ecc7bfd CAMEL-16850: camel-main - Should only clear its internal main configuration if in lightweight mode.
ecc7bfd is described below
commit ecc7bfd0615b460800bb50dc2521f8fd22e7273a
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Aug 6 08:50:45 2021 +0200
CAMEL-16850: camel-main - Should only clear its internal main configuration if in lightweight mode.
---
.../apache/camel/main/MainBootstrapCloseable.java | 36 ++++++++-----
.../apache/camel/main/MainAddDynamicRouteTest.java | 61 ++++++++++++++++++++++
2 files changed, 83 insertions(+), 14 deletions(-)
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainBootstrapCloseable.java b/core/camel-main/src/main/java/org/apache/camel/main/MainBootstrapCloseable.java
index b73b682..a5146dd 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/MainBootstrapCloseable.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/MainBootstrapCloseable.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.main;
+import org.apache.camel.ExtendedCamelContext;
import org.apache.camel.spi.BootstrapCloseable;
public class MainBootstrapCloseable implements BootstrapCloseable {
@@ -28,21 +29,28 @@ public class MainBootstrapCloseable implements BootstrapCloseable {
@Override
public void close() {
- // we are now bootstrapped and can clear up memory
- if (main.initialProperties != null) {
- main.initialProperties.clear();
- main.initialProperties = null;
+ // in lightweight mode then clear up memory after bootstrap
+ boolean lightweight = true;
+ if (main.getCamelContext() != null) {
+ lightweight = main.getCamelContext().adapt(ExtendedCamelContext.class).isLightweight();
}
- if (main.overrideProperties != null) {
- main.overrideProperties.clear();
- main.overrideProperties = null;
- }
- main.wildcardProperties.clear();
- main.wildcardProperties = null;
- // no longer in use
- main.mainConfigurationProperties.close();
- main.mainConfigurationProperties = null;
- main.routesCollector = null;
+ if (lightweight) {
+ if (main.initialProperties != null) {
+ main.initialProperties.clear();
+ main.initialProperties = null;
+ }
+ if (main.overrideProperties != null) {
+ main.overrideProperties.clear();
+ main.overrideProperties = null;
+ }
+ main.wildcardProperties.clear();
+ main.wildcardProperties = null;
+
+ // no longer in use
+ main.mainConfigurationProperties.close();
+ main.mainConfigurationProperties = null;
+ main.routesCollector = null;
+ }
}
}
diff --git a/core/camel-main/src/test/java/org/apache/camel/main/MainAddDynamicRouteTest.java b/core/camel-main/src/test/java/org/apache/camel/main/MainAddDynamicRouteTest.java
new file mode 100644
index 0000000..bb61bfa
--- /dev/null
+++ b/core/camel-main/src/test/java/org/apache/camel/main/MainAddDynamicRouteTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.main;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class MainAddDynamicRouteTest {
+
+ @BindToRegistry("lines")
+ private final List<String> lines = new ArrayList<>();
+
+ @Test
+ public void addDynamicRoute() throws Exception {
+ final Main main = new Main();
+ main.addInitialProperty("prop", "value");
+ main.configure().setDurationMaxMessages(2);
+
+ try (MainConfigurationProperties conf = main.configure()) {
+ conf.addRoutesBuilder(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("timer:one?repeatCount=1")
+ .setBody().simple("{{prop}}").bean(lines, "add")
+ .process(e -> e.getContext().addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("timer:two?repeatCount=1")
+ .setBody().simple("{{prop}}").bean(lines, "add");
+ }
+ }));
+ }
+ });
+
+ main.run();
+
+ Assertions.assertEquals(2, lines.size());
+ Assertions.assertEquals("value", lines.get(0));
+ Assertions.assertEquals("value", lines.get(1));
+ }
+ }
+}