You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gn...@apache.org on 2020/03/25 15:23:01 UTC

[camel] 03/11: Move the clearModelReferences / clearReifiers logic into the ImmutableCamelContext and Main.lightweight property

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

gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 1449f6e815eb6a84f0afab543bd1c8e3f26b9407
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Tue Mar 17 10:48:42 2020 +0100

    Move the clearModelReferences / clearReifiers logic into the ImmutableCamelContext and Main.lightweight property
---
 .../org/apache/camel/ExtendedCamelContext.java     | 36 -----------
 .../camel/impl/engine/AbstractCamelContext.java    | 48 --------------
 .../org/apache/camel/impl/DefaultCamelContext.java | 46 -------------
 .../camel/impl/lw/ImmutableCamelContext.java       | 45 +++++++------
 .../impl/lw/RuntimeImmutableCamelContext.java      | 20 ------
 .../camel-main-configuration-metadata.json         |  3 +-
 .../camel/main/DefaultConfigurationConfigurer.java |  2 -
 .../camel/main/DefaultConfigurationProperties.java | 75 ++++++++--------------
 .../src/main/java/org/apache/camel/main/Main.java  |  7 +-
 9 files changed, 59 insertions(+), 223 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/ExtendedCamelContext.java b/core/camel-api/src/main/java/org/apache/camel/ExtendedCamelContext.java
index a8ef4ea..5e889cb 100644
--- a/core/camel-api/src/main/java/org/apache/camel/ExtendedCamelContext.java
+++ b/core/camel-api/src/main/java/org/apache/camel/ExtendedCamelContext.java
@@ -543,42 +543,6 @@ public interface ExtendedCamelContext extends CamelContext {
      */
     void setConfigurerResolver(ConfigurerResolver configurerResolver);
 
-    /**
-     * Whether it's allowed to add new routes after Camel has been started.
-     * This is enabled by default.
-     * Setting this to false allows Camel to do some internal optimizations to reduce memory footprint.
-     * <p/>
-     * This should only be done on a JVM with a single Camel application (microservice like camel-main, camel-quarkus, camel-spring-boot).
-     * As this affects the entire JVM where Camel JARs are on the classpath.
-     */
-    void setAllowAddingNewRoutes(boolean allowAddingNewRoutes);
-
-    /**
-     * Whether its allowed to add new routes after Camel has been started.
-     * This is enabled by default.
-     * Setting this to false allows Camel to do some internal optimizations to reduce memory footprint.
-     * <p/>
-     * This should only be done on a JVM with a single Camel application (microservice like camel-main, camel-quarkus, camel-spring-boot).
-     * As this affects the entire JVM where Camel JARs are on the classpath.
-     */
-    boolean isAllowAddingNewRoutes();
-
-    /**
-     * Camel context can be configured to remove all references to the model definitions
-     * after it has been started.  It can be used in addition to the {@link #setAllowAddingNewRoutes(boolean)}
-     * method to reduce the footprint.
-     *
-     * @see #isAllowAddingNewRoutes()
-     * @param clearModelReferences
-     */
-    @Experimental
-    void setClearModelReferences(boolean clearModelReferences);
-
-    /**
-     * If references to the model are removed when Camel is started or not.
-     */
-    boolean isClearModelReferences();
-
     RouteController getInternalRouteController();
 
     void addRoute(Route route);
diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index 8f3dacb..2980c01 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -226,8 +226,6 @@ public abstract class AbstractCamelContext extends BaseService
     private Boolean useBreadcrumb = Boolean.FALSE;
     private Boolean allowUseOriginalMessage = Boolean.FALSE;
     private Boolean caseInsensitiveHeaders = Boolean.TRUE;
-    private boolean allowAddingNewRoutes = true;
-    private boolean clearModelReferences;
     private Long delay;
     private ErrorHandlerFactory errorHandlerFactory;
     private Map<String, String> globalOptions = new HashMap<>();
@@ -1157,10 +1155,6 @@ public abstract class AbstractCamelContext extends BaseService
     }
 
     public void addRoute(Route route) {
-        if (isStarted() && !isAllowAddingNewRoutes()) {
-            throw new IllegalArgumentException("Adding new routes after CamelContext has been started is not allowed");
-        }
-
         synchronized (this.routes) {
             this.routes.add(route);
         }
@@ -1168,9 +1162,6 @@ public abstract class AbstractCamelContext extends BaseService
 
     @Override
     public void addRoutes(final RoutesBuilder builder) throws Exception {
-        if (isStarted() && !isAllowAddingNewRoutes()) {
-            throw new IllegalArgumentException("Adding new routes after CamelContext has been started is not allowed");
-        }
         try (LifecycleHelper helper = new LifecycleHelper()) {
             init();
             LOG.debug("Adding routes from builder: {}", builder);
@@ -1938,24 +1929,6 @@ public abstract class AbstractCamelContext extends BaseService
     }
 
     @Override
-    public boolean isAllowAddingNewRoutes() {
-        return allowAddingNewRoutes;
-    }
-
-    @Override
-    public void setAllowAddingNewRoutes(boolean allowAddingNewRoutes) {
-        this.allowAddingNewRoutes = allowAddingNewRoutes;
-    }
-
-    public boolean isClearModelReferences() {
-        return clearModelReferences;
-    }
-
-    public void setClearModelReferences(boolean clearModelReferences) {
-        this.clearModelReferences = clearModelReferences;
-    }
-
-    @Override
     public Registry getRegistry() {
         if (registry == null) {
             synchronized (lock) {
@@ -2551,16 +2524,6 @@ public abstract class AbstractCamelContext extends BaseService
             }
         }
 
-        if (!isAllowAddingNewRoutes()) {
-            LOG.info("Adding new routes after CamelContext has started is not allowed");
-            disallowAddingNewRoutes();
-        }
-
-        if (isClearModelReferences()) {
-            LOG.info("Clearing model references");
-            clearModelReferences();
-        }
-
         if (LOG.isInfoEnabled()) {
             // count how many routes are actually started
             int started = 0;
@@ -2898,17 +2861,6 @@ public abstract class AbstractCamelContext extends BaseService
         CamelContextTracker.notifyContextDestroyed(this);
     }
 
-    /**
-     * Strategy invoked when adding new routes after CamelContext has been started is not allowed.
-     * This is used to do some internal optimizations.
-     */
-    protected void disallowAddingNewRoutes() {
-        ReifierStrategy.clearReifiers();
-    }
-
-    protected void clearModelReferences() {
-    }
-
     public void startRouteDefinitions() throws Exception {
     }
 
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index e4fa1d7..3c93ab0 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -16,9 +16,6 @@
  */
 package org.apache.camel.impl;
 
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
@@ -27,14 +24,12 @@ import java.util.function.Function;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Expression;
 import org.apache.camel.FailedToStartRouteException;
-import org.apache.camel.Navigate;
 import org.apache.camel.Predicate;
 import org.apache.camel.Processor;
 import org.apache.camel.Route;
 import org.apache.camel.ValueHolder;
 import org.apache.camel.builder.AdviceWithRouteBuilder;
 import org.apache.camel.health.HealthCheckRegistry;
-import org.apache.camel.impl.engine.DefaultRoute;
 import org.apache.camel.impl.engine.RouteService;
 import org.apache.camel.impl.engine.SimpleCamelContext;
 import org.apache.camel.impl.transformer.TransformerKey;
@@ -52,7 +47,6 @@ import org.apache.camel.model.language.ExpressionDefinition;
 import org.apache.camel.model.rest.RestDefinition;
 import org.apache.camel.model.transformer.TransformerDefinition;
 import org.apache.camel.model.validator.ValidatorDefinition;
-import org.apache.camel.processor.channel.DefaultChannel;
 import org.apache.camel.reifier.RouteReifier;
 import org.apache.camel.reifier.dataformat.DataFormatReifier;
 import org.apache.camel.reifier.errorhandler.ErrorHandlerReifier;
@@ -129,17 +123,11 @@ public class DefaultCamelContext extends SimpleCamelContext implements ModelCame
 
     @Override
     public void addRouteDefinitions(Collection<RouteDefinition> routeDefinitions) throws Exception {
-        if (isStarted() && !isAllowAddingNewRoutes()) {
-            throw new IllegalArgumentException("Adding new routes after CamelContext has been started is not allowed");
-        }
         model.addRouteDefinitions(routeDefinitions);
     }
 
     @Override
     public void addRouteDefinition(RouteDefinition routeDefinition) throws Exception {
-        if (isStarted() && !isAllowAddingNewRoutes()) {
-            throw new IllegalArgumentException("Adding new routes after CamelContext has been started is not allowed");
-        }
         model.addRouteDefinition(routeDefinition);
     }
 
@@ -160,9 +148,6 @@ public class DefaultCamelContext extends SimpleCamelContext implements ModelCame
 
     @Override
     public void addRestDefinitions(Collection<RestDefinition> restDefinitions, boolean addToRoutes) throws Exception {
-        if (isStarted() && !isAllowAddingNewRoutes()) {
-            throw new IllegalArgumentException("Adding new routes after CamelContext has been started is not allowed");
-        }
         model.addRestDefinitions(restDefinitions, addToRoutes);
     }
 
@@ -382,37 +367,6 @@ public class DefaultCamelContext extends SimpleCamelContext implements ModelCame
     }
 
     @Override
-    protected void clearModelReferences() {
-        model = (Model) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Model.class }, new InvocationHandler() {
-            @Override
-            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
-                throw new UnsupportedOperationException("Model invocations are not supported at runtime");
-            }
-        });
-        for (Route route : getRoutes()) {
-            clearModelReferences(route);
-        }
-    }
-
-    private void clearModelReferences(Route r) {
-        if (r instanceof DefaultRoute) {
-            ((DefaultRoute) r).clearModelReferences();
-        }
-        clearModelReferences(r.navigate());
-    }
-
-    private void clearModelReferences(Navigate<Processor> nav) {
-        for (Processor processor : nav.next()) {
-            if (processor instanceof DefaultChannel) {
-                ((DefaultChannel) processor).clearModelReferences();
-            }
-            if (processor instanceof Navigate) {
-                clearModelReferences((Navigate<Processor>) processor);
-            }
-        }
-    }
-
-    @Override
     public Processor createErrorHandler(Route route, Processor processor) throws Exception {
         return ErrorHandlerReifier.reifier(route, route.getErrorHandlerFactory())
                 .createErrorHandler(processor);
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/ImmutableCamelContext.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/ImmutableCamelContext.java
index 62537e4..36cd754 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/ImmutableCamelContext.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/ImmutableCamelContext.java
@@ -38,6 +38,7 @@ import org.apache.camel.Expression;
 import org.apache.camel.ExtendedCamelContext;
 import org.apache.camel.FluentProducerTemplate;
 import org.apache.camel.GlobalEndpointConfiguration;
+import org.apache.camel.Navigate;
 import org.apache.camel.NoSuchLanguageException;
 import org.apache.camel.Predicate;
 import org.apache.camel.Processor;
@@ -53,6 +54,7 @@ import org.apache.camel.ValueHolder;
 import org.apache.camel.builder.AdviceWithRouteBuilder;
 import org.apache.camel.catalog.RuntimeCamelCatalog;
 import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.engine.DefaultRoute;
 import org.apache.camel.model.DataFormatDefinition;
 import org.apache.camel.model.HystrixConfigurationDefinition;
 import org.apache.camel.model.ModelCamelContext;
@@ -64,6 +66,7 @@ import org.apache.camel.model.language.ExpressionDefinition;
 import org.apache.camel.model.rest.RestDefinition;
 import org.apache.camel.model.transformer.TransformerDefinition;
 import org.apache.camel.model.validator.ValidatorDefinition;
+import org.apache.camel.processor.channel.DefaultChannel;
 import org.apache.camel.spi.AnnotationBasedProcessorFactory;
 import org.apache.camel.spi.AsyncProcessorAwaitManager;
 import org.apache.camel.spi.BeanIntrospection;
@@ -1394,27 +1397,6 @@ public class ImmutableCamelContext implements ExtendedCamelContext, CatalogCamel
     }
 
     @Override
-    public void setAllowAddingNewRoutes(boolean allowAddingNewRoutes) {
-        getExtendedCamelContext().setAllowAddingNewRoutes(allowAddingNewRoutes);
-    }
-
-    @Override
-    public boolean isAllowAddingNewRoutes() {
-        return getExtendedCamelContext().isAllowAddingNewRoutes();
-    }
-
-    @Override
-    @Experimental
-    public void setClearModelReferences(boolean clearModelReferences) {
-        getExtendedCamelContext().setClearModelReferences(clearModelReferences);
-    }
-
-    @Override
-    public boolean isClearModelReferences() {
-        return getExtendedCamelContext().isClearModelReferences();
-    }
-
-    @Override
     public RouteController getInternalRouteController() {
         return getExtendedCamelContext().getInternalRouteController();
     }
@@ -1675,9 +1657,30 @@ public class ImmutableCamelContext implements ExtendedCamelContext, CatalogCamel
         }
         delegate.setAutoStartup(false);
         delegate.start();
+        for (Route route : delegate.getRoutes()) {
+            clearModelReferences(route);
+        }
         delegate = new RuntimeImmutableCamelContext(this, delegate);
     }
 
+    private void clearModelReferences(Route r) {
+        if (r instanceof DefaultRoute) {
+            ((DefaultRoute) r).clearModelReferences();
+        }
+        clearModelReferences(r.navigate());
+    }
+
+    private void clearModelReferences(Navigate<Processor> nav) {
+        for (Processor processor : nav.next()) {
+            if (processor instanceof DefaultChannel) {
+                ((DefaultChannel) processor).clearModelReferences();
+            }
+            if (processor instanceof Navigate) {
+                clearModelReferences((Navigate<Processor>) processor);
+            }
+        }
+    }
+
     public void startImmutable() {
         delegate.start();
     }
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/RuntimeImmutableCamelContext.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/RuntimeImmutableCamelContext.java
index b397214..e7ed47d 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/RuntimeImmutableCamelContext.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/RuntimeImmutableCamelContext.java
@@ -1262,16 +1262,6 @@ public class RuntimeImmutableCamelContext implements ExtendedCamelContext, Catal
     }
 
     @Override
-    public boolean isAllowAddingNewRoutes() {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public boolean isClearModelReferences() {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
     public void addRoute(Route route) {
         throw new UnsupportedOperationException();
     }
@@ -1523,16 +1513,6 @@ public class RuntimeImmutableCamelContext implements ExtendedCamelContext, Catal
     }
 
     @Override
-    public void setAllowAddingNewRoutes(boolean allowAddingNewRoutes) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public void setClearModelReferences(boolean clearModelReferences) {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
     public XMLRoutesDefinitionLoader getXMLRoutesDefinitionLoader() {
         throw new UnsupportedOperationException();
     }
diff --git a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
index 7d8987f..0cfdb35 100644
--- a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
+++ b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
@@ -6,7 +6,6 @@
     { "name": "camel.rest", "description": "camel-rest configurations.", "sourceType": "org.apache.camel.spi.RestConfiguration" }
   ],
   "properties": [
-    { "name": "camel.main.allowAddingNewRoutes", "description": "Whether its allowed to add new routes after Camel has been started. This is enabled by default. Setting this to false allows Camel to do some internal optimizations to reduce memory footprint. This should only be done on a JVM with a single Camel application (microservice like camel-main, camel-quarkus, camel-spring-boot). As this affects the entire JVM where Camel JARs are on the classpath.", "sourceType": "org.apache.came [...]
     { "name": "camel.main.allowUseOriginalMessage", "description": "Sets whether to allow access to the original message from Camel's error handler, or from org.apache.camel.spi.UnitOfWork.getOriginalInMessage(). Turning this off can optimize performance, as defensive copy of the original message is not needed. Default is false.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", "javaType": "boolean" },
     { "name": "camel.main.autoConfigurationEnabled", "description": "Whether auto configuration of components, dataformats, languages is enabled or not. When enabled the configuration parameters are loaded from the properties component and optionally from the classpath file META-INF\/services\/org\/apache\/camel\/autowire.properties. You can prefix the parameters in the properties file with: - camel.component.name.option1=value1 - camel.component.name.option2=value2 - camel.dataformat.na [...]
     { "name": "camel.main.autoConfigurationEnvironmentVariablesEnabled", "description": "Whether auto configuration should include OS environment variables as well. When enabled this allows to overrule any configuration using an OS environment variable. For example to set a shutdown timeout of 5 seconds: CAMEL_MAIN_SHUTDOWNTIMEOUT=5. This option is default enabled.", "sourceType": "org.apache.camel.main.MainConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue [...]
@@ -21,7 +20,6 @@
     { "name": "camel.main.beanIntrospectionExtendedStatistics", "description": "Sets whether bean introspection uses extended statistics. The default is false.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", "javaType": "boolean" },
     { "name": "camel.main.beanIntrospectionLoggingLevel", "description": "Sets the logging level used by bean introspection, logging activity of its usage. The default is TRACE.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "object", "javaType": "org.apache.camel.LoggingLevel", "enum": [ "ERROR", "WARN", "INFO", "DEBUG", "TRACE", "OFF" ] },
     { "name": "camel.main.caseInsensitiveHeaders", "description": "Whether to use case sensitive or insensitive headers. Important: When using case sensitive (this is set to false). Then the map is case sensitive which means headers such as content-type and Content-Type are two different keys which can be a problem for some protocols such as HTTP based, which rely on case insensitive headers. However case sensitive implementations can yield faster performance. Therefore use case sensitiv [...]
-    { "name": "camel.main.clearModelReferences", "description": null, "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", "javaType": "boolean" },
     { "name": "camel.main.consumerTemplateCacheSize", "description": "Consumer template endpoints cache size.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "integer", "javaType": "int", "defaultValue": 1000 },
     { "name": "camel.main.durationHitExitCode", "description": "Sets the exit code for the application if duration was hit", "sourceType": "org.apache.camel.main.MainConfigurationProperties", "type": "integer", "javaType": "int" },
     { "name": "camel.main.durationMaxIdleSeconds", "description": "To specify for how long time in seconds Camel can be idle before automatic terminating the JVM. You can use this to run Camel for a short while.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "integer", "javaType": "int" },
@@ -40,6 +38,7 @@
     { "name": "camel.main.jmxEnabled", "description": "Enable JMX in your Camel application.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": true },
     { "name": "camel.main.jmxManagementNamePattern", "description": "The naming pattern for creating the CamelContext JMX management name. The default pattern is #name#", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "string", "javaType": "java.lang.String", "defaultValue": "#name#" },
     { "name": "camel.main.jmxManagementStatisticsLevel", "description": "Sets the JMX statistics level The level can be set to Extended to gather additional information The default value is Default.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "object", "javaType": "org.apache.camel.ManagementStatisticsLevel", "defaultValue": "ManagementStatisticsLevel.Default", "enum": [ "Extended", "Default", "RoutesOnly", "Off" ] },
+    { "name": "camel.main.lightweight", "description": "Configure the context to be lightweight. This will trigger some optimizations and memory reduction options. Lightweight context have some limitations. At this moment, dynamic endpoint destinations are not supported.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", "javaType": "boolean" },
     { "name": "camel.main.loadTypeConverters", "description": "Whether to load custom type converters by scanning classpath. This is used for backwards compatibility with Camel 2.x. Its recommended to migrate to use fast type converter loading by setting Converter(loader = true) on your custom type converter classes.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", "javaType": "boolean" },
     { "name": "camel.main.logDebugMaxChars", "description": "Is used to limit the maximum length of the logging Camel message bodies. If the message body is longer than the limit, the log message is clipped. Use -1 to have unlimited length. Use for example 1000 to log at most 1000 characters.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "integer", "javaType": "int" },
     { "name": "camel.main.logExhaustedMessageBody", "description": "Sets whether to log exhausted message body with message history. Default is false.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", "javaType": "boolean" },
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java
index a576f72..a76def9 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java
@@ -153,8 +153,6 @@ public final class DefaultConfigurationConfigurer {
         camelContext.setUseMDCLogging(config.isUseMdcLogging());
         camelContext.setMDCLoggingKeysPattern(config.getMdcLoggingKeysPattern());
         camelContext.setLoadTypeConverters(config.isLoadTypeConverters());
-        ecc.setAllowAddingNewRoutes(config.isAllowAddingNewRoutes());
-        ecc.setClearModelReferences(config.isClearModelReferences());
 
         if (camelContext.getManagementStrategy().getManagementAgent() != null) {
             camelContext.getManagementStrategy().getManagementAgent().setEndpointRuntimeStatisticsEnabled(config.isEndpointRuntimeStatisticsEnabled());
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
index cc2b2d5..58777be 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
@@ -66,8 +66,6 @@ public abstract class DefaultConfigurationProperties<T> {
     private boolean endpointBasicPropertyBinding;
     private boolean useDataType;
     private boolean useBreadcrumb;
-    private boolean allowAddingNewRoutes = true;
-    private boolean clearModelReferences;
     private ManagementStatisticsLevel jmxManagementStatisticsLevel = ManagementStatisticsLevel.Default;
     private String jmxManagementNamePattern = "#name#";
     private boolean jmxCreateConnector;
@@ -83,6 +81,7 @@ public abstract class DefaultConfigurationProperties<T> {
     private String javaRoutesExcludePattern;
     private String xmlRoutes = "classpath:camel/*.xml";
     private String xmlRests = "classpath:camel-rest/*.xml";
+    private boolean lightweight;
 
     // getter and setters
     // --------------------------------------------------------------
@@ -634,38 +633,6 @@ public abstract class DefaultConfigurationProperties<T> {
         this.useBreadcrumb = useBreadcrumb;
     }
 
-    /**
-     * Whether its allowed to add new routes after Camel has been started.
-     * This is enabled by default.
-     * Setting this to false allows Camel to do some internal optimizations to reduce memory footprint.
-     * <p/>
-     * This should only be done on a JVM with a single Camel application (microservice like camel-main, camel-quarkus, camel-spring-boot).
-     * As this affects the entire JVM where Camel JARs are on the classpath.
-     */
-    public boolean isAllowAddingNewRoutes() {
-        return allowAddingNewRoutes;
-    }
-
-    /**
-     * Whether its allowed to add new routes after Camel has been started.
-     * This is enabled by default.
-     * Setting this to false allows Camel to do some internal optimizations to reduce memory footprint.
-     * <p/>
-     * This should only be done on a JVM with a single Camel application (microservice like camel-main, camel-quarkus, camel-spring-boot).
-     * As this affects the entire JVM where Camel JARs are on the classpath.
-     */
-    public void setAllowAddingNewRoutes(boolean allowAddingNewRoutes) {
-        this.allowAddingNewRoutes = allowAddingNewRoutes;
-    }
-
-    public boolean isClearModelReferences() {
-        return clearModelReferences;
-    }
-
-    public void setClearModelReferences(boolean clearModelReferences) {
-        this.clearModelReferences = clearModelReferences;
-    }
-
     public ManagementStatisticsLevel getJmxManagementStatisticsLevel() {
         return jmxManagementStatisticsLevel;
     }
@@ -924,6 +891,19 @@ public abstract class DefaultConfigurationProperties<T> {
         this.xmlRests = xmlRests;
     }
 
+    public boolean isLightweight() {
+        return lightweight;
+    }
+
+    /**
+     * Configure the context to be lightweight.  This will trigger some optimizations
+     * and memory reduction options.  Lightweight context have some limitations.  At
+     * this moment, dynamic endpoint destinations are not supported.
+     */
+    public void setLightweight(boolean lightweight) {
+        this.lightweight = lightweight;
+    }
+
     // fluent builders
     // --------------------------------------------------------------
 
@@ -1332,19 +1312,6 @@ public abstract class DefaultConfigurationProperties<T> {
     }
 
     /**
-     * Whether its allowed to add new routes after Camel has been started.
-     * This is enabled by default.
-     * Setting this to false allows Camel to do some internal optimizations to reduce memory footprint.
-     * <p/>
-     * This should only be done on a JVM with a single Camel application (microservice like camel-main, camel-quarkus, camel-spring-boot).
-     * As this affects the entire JVM where Camel JARs are on the classpath.
-     */
-    public T withAllowAddingNewRoutes(boolean allowAddingNewRoutes) {
-        this.allowAddingNewRoutes = allowAddingNewRoutes;
-        return (T) this;
-    }
-
-    /**
      * Set whether breadcrumb is enabled.
      * The default value is false.
      */
@@ -1580,4 +1547,18 @@ public abstract class DefaultConfigurationProperties<T> {
         this.xmlRests = xmlRests;
         return (T) this;
     }
+
+    /*
+     * Configure the context to be lightweight.  This will trigger some optimizations
+     * and memory reduction options.
+     * <p/>
+     * Lightweight context have some limitations.  At the moment, dynamic endpoint
+     * destinations are not supported.  Also, this should only be done on a JVM with
+     * a single Camel application (microservice like camel-main, camel-quarkus, camel-spring-boot).
+     * As this affects the entire JVM where Camel JARs are on the classpath.
+     */
+    public T withLightweight(boolean lightweight) {
+        this.lightweight = lightweight;
+        return (T) this;
+    }
 }
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/Main.java b/core/camel-main/src/main/java/org/apache/camel/main/Main.java
index ac51b86..8721427 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/Main.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/Main.java
@@ -21,6 +21,7 @@ import java.util.Map;
 import org.apache.camel.CamelContext;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.lw.ImmutableCamelContext;
 import org.apache.camel.spi.Registry;
 
 /**
@@ -142,7 +143,11 @@ public class Main extends MainCommandLineSupport {
 
     @Override
     protected CamelContext createCamelContext() {
-        return new DefaultCamelContext(registry);
+        if (mainConfigurationProperties.isLightweight()) {
+            return new ImmutableCamelContext(registry);
+        } else {
+            return new DefaultCamelContext(registry);
+        }
     }
 
 }