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 ac792d338517 CAMEL-25631: camel-core - Deprecate
Route.clearRouteModel() and stop calling it from RouteReifier
ac792d338517 is described below
commit ac792d3385174b63acd5a18efa8dee92830c4699
Author: Guillaume Nodet <[email protected]>
AuthorDate: Fri Oct 16 16:59:56 2026 +0200
CAMEL-25631: camel-core - Deprecate Route.clearRouteModel() and stop
calling it from RouteReifier
Deprecate Route.clearRouteModel() (since 4.24.0, for removal) and turn it
into a default no-op. RouteReifier no longer calls it, so the route model
returned by Route.getRoute() and the error handler factory are kept at
runtime, also for routes added after the CamelContext has started.
DefaultRoute.route is now final and the getRoute() javadoc describes what it
returns. RouteModelRetainedTest covers routes created at startup and routes
added later, and the 4.24 upgrade guide documents the deprecation.
Closes #27835
Co-authored-by: Hermes Agent <[email protected]>
---
.../src/main/java/org/apache/camel/Route.java | 16 +++--
.../org/apache/camel/impl/engine/DefaultRoute.java | 9 +--
.../org/apache/camel/reifier/RouteReifier.java | 7 ---
.../camel/builder/RouteModelRetainedTest.java | 73 ++++++++++++++++++++++
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 12 ++++
5 files changed, 96 insertions(+), 21 deletions(-)
diff --git a/core/camel-api/src/main/java/org/apache/camel/Route.java
b/core/camel-api/src/main/java/org/apache/camel/Route.java
index 8c51ca213638..7d1ca3dd1819 100644
--- a/core/camel-api/src/main/java/org/apache/camel/Route.java
+++ b/core/camel-api/src/main/java/org/apache/camel/Route.java
@@ -378,19 +378,23 @@ public interface Route extends RuntimeConfiguration {
String getRouteNote();
/**
- * Get the route type.
+ * Gets the route model (such as the route definition) this route was
created from.
*
- * Important: is null after the route has been created.
- *
- * @return the route type during creation of the route, is null after the
route has been created.
+ * @return the route model, or null if this route was not created from a
model
*/
@Nullable
NamedNode getRoute();
/**
- * Clears the route model when its no longer needed.
+ * Previously cleared the route model after the route was created. This
method is now a no-op.
+ *
+ * @deprecated since 4.24.0 - the route model is retained at runtime; this
method is a no-op and will be removed in
+ * a later release.
*/
- void clearRouteModel();
+ @Deprecated(since = "4.24.0", forRemoval = true)
+ default void clearRouteModel() {
+ // no-op: the route model is now retained at runtime
+ }
//
// CREATION TIME
diff --git
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultRoute.java
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultRoute.java
index 8ef3ff027ac3..5bf89e352077 100644
---
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultRoute.java
+++
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultRoute.java
@@ -74,7 +74,7 @@ import org.apache.camel.util.TimeUtils;
public class DefaultRoute extends ServiceSupport implements Route {
private final CamelContext camelContext;
- private NamedNode route;
+ private final NamedNode route;
private final String routeId;
private final String routeDescription;
private final String routeNote;
@@ -375,13 +375,6 @@ public class DefaultRoute extends ServiceSupport
implements Route {
return route;
}
- @Override
- public void clearRouteModel() {
- route = null;
- errorHandlerFactory = null;
- errorHandlers.clear();
- }
-
@Override
public String getRouteId() {
return routeId;
diff --git
a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/RouteReifier.java
b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/RouteReifier.java
index 82b7298077d5..eec2f04b69cf 100644
---
a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/RouteReifier.java
+++
b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/RouteReifier.java
@@ -35,7 +35,6 @@ import org.apache.camel.Route;
import org.apache.camel.RouteAware;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.Service;
-import org.apache.camel.ServiceStatus;
import org.apache.camel.ShutdownRoute;
import org.apache.camel.ShutdownRunningTask;
import org.apache.camel.StartupStep;
@@ -390,12 +389,6 @@ public class RouteReifier extends
ProcessorReifier<RouteDefinition> {
builder, null);
prepareErrorHandlerAware(route, errorHandler);
- // only during startup phase
- if (camelContext.getStatus().ordinal() <
ServiceStatus.Started.ordinal()) {
- // okay route has been created from the model, then the model is
no longer needed, and we can de-reference
-
camelContext.getCamelContextExtension().addBootstrap(route::clearRouteModel);
- }
-
if (definition.getRouteTemplateContext() != null) {
// make route stop beans from the local repository (route
templates / kamelets)
Service wrapper = new ServiceSupport() {
diff --git
a/core/camel-core/src/test/java/org/apache/camel/builder/RouteModelRetainedTest.java
b/core/camel-core/src/test/java/org/apache/camel/builder/RouteModelRetainedTest.java
new file mode 100644
index 000000000000..d72be2de99ce
--- /dev/null
+++
b/core/camel-core/src/test/java/org/apache/camel/builder/RouteModelRetainedTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.builder;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Route;
+import org.apache.camel.model.RouteDefinition;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * Verifies that {@link Route#getRoute()} and {@link
Route#getErrorHandlerFactory()} are retained at runtime for routes
+ * created at startup (CAMEL-25631).
+ */
+public class RouteModelRetainedTest extends ContextTestSupport {
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:startup")
+ .routeId("startup-route")
+ .to("mock:result");
+ }
+ };
+ }
+
+ @Test
+ public void testStartupRouteModelRetained() {
+ Route route = context.getRoute("startup-route");
+ assertNotNull(route, "Route should exist");
+ assertInstanceOf(RouteDefinition.class, route.getRoute(),
+ "getRoute() should return a RouteDefinition for a startup
route");
+ assertNotNull(route.getErrorHandlerFactory(),
+ "getErrorHandlerFactory() should not be null for a startup
route");
+ }
+
+ @Test
+ public void testRuntimeAddedRouteModelRetained() throws Exception {
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:runtime")
+ .routeId("runtime-route")
+ .to("mock:result");
+ }
+ });
+
+ Route route = context.getRoute("runtime-route");
+ assertNotNull(route, "Route should exist");
+ assertInstanceOf(RouteDefinition.class, route.getRoute(),
+ "getRoute() should return a RouteDefinition for a
runtime-added route");
+ assertNotNull(route.getErrorHandlerFactory(),
+ "getErrorHandlerFactory() should not be null for a
runtime-added route");
+ }
+}
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index 0814687b4a00..c0361fcc4764 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -13,6 +13,18 @@ See the xref:camel-upgrade-recipes-tool.adoc[documentation]
page for details.
== Upgrading Camel 4.23 to 4.24
+=== camel-core - Route.clearRouteModel() is deprecated
+
+The `Route.clearRouteModel()` method is deprecated and is now a no-op. It will
be removed in a later release.
+
+This method dropped the references a runtime route held to its model (the
route definition, the error handler factory
+and the error handlers) once the route was created at startup. The
`CamelContext` already keeps the route definitions
+in its model, so clearing them on the route saved little memory at the cost of
making `Route.getRoute()` and
+`Route.getErrorHandlerFactory()` return `null` for routes created at startup
(but not for routes added after startup).
+
+Applications that called `Route.clearRouteModel()` directly can remove the
call. Implementations of the `Route` interface
+that override `clearRouteModel()` can remove the override.
+
=== camel-semantic - expert artifacts
TypeSafe AI Semantic applications must add
`org.apache.camel:camel-semantic-typesafe-ai`.