You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/10/17 11:20:53 UTC
[camel] 05/06: CAMEL-19998: cleanup shutdown strategy API
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 8504874a173846225a57509a42b34eb8b84132a5
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Oct 17 09:33:36 2023 +0200
CAMEL-19998: cleanup shutdown strategy API
---
.../camel/impl/engine/AbstractCamelContext.java | 19 ++++++++-----------
.../impl/engine/DefaultCamelContextExtension.java | 17 +++++++++++++++++
2 files changed, 25 insertions(+), 11 deletions(-)
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 e4f86be0781..38423b8f153 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
@@ -261,7 +261,6 @@ public abstract class AbstractCamelContext extends BaseService
private Boolean autowiredEnabled = Boolean.TRUE;
private Long delay;
private Map<String, String> globalOptions = new HashMap<>();
- private volatile ShutdownStrategy shutdownStrategy;
private volatile ExecutorServiceManager executorServiceManager;
private EndpointRegistry<NormalizedUri> endpoints;
private RuntimeEndpointRegistry runtimeEndpointRegistry;
@@ -1077,6 +1076,8 @@ public abstract class AbstractCamelContext extends BaseService
// stop all routes in reverse order that they were started
Comparator<RouteStartupOrder> comparator = Comparator.comparingInt(RouteStartupOrder::getStartupOrder);
+
+ final ShutdownStrategy shutdownStrategy = camelContextExtension.getShutdownStrategy();
if (shutdownStrategy == null || shutdownStrategy.isShutdownRoutesInReverseOrder()) {
comparator = comparator.reversed();
}
@@ -1091,6 +1092,7 @@ public abstract class AbstractCamelContext extends BaseService
public void removeAllRoutes() throws Exception {
// stop all routes in reverse order that they were started
Comparator<RouteStartupOrder> comparator = Comparator.comparingInt(RouteStartupOrder::getStartupOrder);
+ final ShutdownStrategy shutdownStrategy = getShutdownStrategy();
if (shutdownStrategy == null || shutdownStrategy.isShutdownRoutesInReverseOrder()) {
comparator = comparator.reversed();
}
@@ -2131,7 +2133,7 @@ public abstract class AbstractCamelContext extends BaseService
}
// init the shutdown strategy
- this.shutdownStrategy = getShutdownStrategy();
+ final ShutdownStrategy shutdownStrategy = getShutdownStrategy();
if (startupSummaryLevel == StartupSummaryLevel.Verbose) {
// verbose startup should let route controller do the route shutdown logging
if (shutdownStrategy != null && shutdownStrategy.getLoggingLevel().ordinal() < LoggingLevel.INFO.ordinal()) {
@@ -2734,6 +2736,7 @@ public abstract class AbstractCamelContext extends BaseService
@Override
protected void doStop() throws Exception {
stopWatch.restart();
+ final ShutdownStrategy shutdownStrategy = getShutdownStrategy();
if (startupSummaryLevel != StartupSummaryLevel.Oneline && startupSummaryLevel != StartupSummaryLevel.Off) {
if (shutdownStrategy != null && shutdownStrategy.getTimeUnit() != null) {
@@ -2908,6 +2911,7 @@ public abstract class AbstractCamelContext extends BaseService
int forced = 0;
List<String> lines = new ArrayList<>();
+ final ShutdownStrategy shutdownStrategy = camelContextExtension.getShutdownStrategy();
if (shutdownStrategy != null && shutdownStrategy.isShutdownRoutesInReverseOrder()) {
routeStartupOrder.sort(Comparator.comparingInt(RouteStartupOrder::getStartupOrder).reversed());
} else {
@@ -3487,19 +3491,12 @@ public abstract class AbstractCamelContext extends BaseService
@Override
public ShutdownStrategy getShutdownStrategy() {
- if (shutdownStrategy == null) {
- synchronized (lock) {
- if (shutdownStrategy == null) {
- setShutdownStrategy(createShutdownStrategy());
- }
- }
- }
- return shutdownStrategy;
+ return camelContextExtension.getShutdownStrategy();
}
@Override
public void setShutdownStrategy(ShutdownStrategy shutdownStrategy) {
- this.shutdownStrategy = internalServiceManager.addService(shutdownStrategy);
+ camelContextExtension.setShutdownStrategy(shutdownStrategy);
}
@Override
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultCamelContextExtension.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultCamelContextExtension.java
index 7fe9c766e05..c9206743d5b 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultCamelContextExtension.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultCamelContextExtension.java
@@ -70,6 +70,7 @@ import org.apache.camel.spi.RestRegistry;
import org.apache.camel.spi.RestRegistryFactory;
import org.apache.camel.spi.RouteController;
import org.apache.camel.spi.RouteStartupOrder;
+import org.apache.camel.spi.ShutdownStrategy;
import org.apache.camel.spi.StartupStepRecorder;
import org.apache.camel.spi.StreamCachingStrategy;
import org.apache.camel.spi.Tracer;
@@ -125,6 +126,7 @@ class DefaultCamelContextExtension implements ExtendedCamelContext {
private volatile TypeConverterRegistry typeConverterRegistry;
private volatile TypeConverter typeConverter;
private volatile RouteController routeController;
+ private volatile ShutdownStrategy shutdownStrategy;
private volatile Injector injector;
@@ -872,6 +874,21 @@ class DefaultCamelContextExtension implements ExtendedCamelContext {
this.routeController = camelContext.getInternalServiceManager().addService(routeController);
}
+ ShutdownStrategy getShutdownStrategy() {
+ if (shutdownStrategy == null) {
+ synchronized (lock) {
+ if (shutdownStrategy == null) {
+ setShutdownStrategy(camelContext.createShutdownStrategy());
+ }
+ }
+ }
+ return shutdownStrategy;
+ }
+
+ void setShutdownStrategy(ShutdownStrategy shutdownStrategy) {
+ this.shutdownStrategy = camelContext.getInternalServiceManager().addService(shutdownStrategy);
+ }
+
@Override
public RouteController getInternalRouteController() {
return internalRouteController;