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/03/13 11:26:16 UTC
[camel] branch master updated: CAMEL-16348: camel-core - Optimize
shutdown strategy forceShutdown check
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 6628771 CAMEL-16348: camel-core - Optimize shutdown strategy forceShutdown check
6628771 is described below
commit 66287711c48470d7a3e254e9133f116d80ec0b9b
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Mar 13 12:25:32 2021 +0100
CAMEL-16348: camel-core - Optimize shutdown strategy forceShutdown check
---
.../java/org/apache/camel/spi/ShutdownStrategy.java | 15 ++-------------
.../camel/impl/engine/CamelInternalProcessor.java | 3 +--
.../camel/impl/engine/DefaultShutdownStrategy.java | 8 ++++----
.../impl/engine/SharedCamelInternalProcessor.java | 19 +++++++------------
.../java/org/apache/camel/processor/Throttler.java | 2 +-
.../errorhandler/RedeliveryErrorHandler.java | 6 ++----
.../processor/loadbalancer/FailOverLoadBalancer.java | 2 +-
7 files changed, 18 insertions(+), 37 deletions(-)
diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/ShutdownStrategy.java b/core/camel-api/src/main/java/org/apache/camel/spi/ShutdownStrategy.java
index 183161f..507f090 100644
--- a/core/camel-api/src/main/java/org/apache/camel/spi/ShutdownStrategy.java
+++ b/core/camel-api/src/main/java/org/apache/camel/spi/ShutdownStrategy.java
@@ -21,7 +21,6 @@ import java.util.concurrent.TimeUnit;
import org.apache.camel.CamelContext;
import org.apache.camel.LoggingLevel;
-import org.apache.camel.Service;
import org.apache.camel.StaticService;
/**
@@ -224,19 +223,9 @@ public interface ShutdownStrategy extends StaticService {
boolean isLogInflightExchangesOnTimeout();
/**
- * Whether a service is forced to shutdown.
- * <p/>
- * Can be used to signal to services that they are no longer allowed to run, such as if a forced shutdown is
- * currently in progress.
- * <p/>
- * For example the Camel {@link org.apache.camel.processor.RedeliveryErrorHandler} uses this information to know if
- * a forced shutdown is in progress, and then break out of redelivery attempts.
- *
- * @param service the service
- * @return <tt>true</tt> indicates the service is to be forced to shutdown, <tt>false</tt> the service can
- * keep running.
+ * Whether the shutdown strategy is forcing to shutdown
*/
- boolean forceShutdown(Service service);
+ boolean isForceShutdown();
/**
* Whether a timeout has occurred during a shutdown.
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/CamelInternalProcessor.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/CamelInternalProcessor.java
index b13861f..8f367eb 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/CamelInternalProcessor.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/CamelInternalProcessor.java
@@ -292,8 +292,7 @@ public class CamelInternalProcessor extends DelegateAsyncProcessor implements In
return true;
}
- boolean forceShutdown = shutdownStrategy.forceShutdown(this);
- if (forceShutdown) {
+ if (shutdownStrategy.isForceShutdown()) {
String msg = "Run not allowed as ShutdownStrategy is forcing shutting down, will reject executing exchange: "
+ exchange;
LOG.debug(msg);
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultShutdownStrategy.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultShutdownStrategy.java
index bfa8ff2..003b703 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultShutdownStrategy.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultShutdownStrategy.java
@@ -127,7 +127,7 @@ public class DefaultShutdownStrategy extends ServiceSupport implements ShutdownS
private boolean suppressLoggingOnTimeout;
private boolean logInflightExchangesOnTimeout = true;
- private volatile boolean forceShutdown;
+ private boolean forceShutdown;
private final AtomicBoolean timeoutOccurred = new AtomicBoolean();
private volatile Future<?> currentShutdownTaskFuture;
@@ -280,7 +280,7 @@ public class DefaultShutdownStrategy extends ServiceSupport implements ShutdownS
}
@Override
- public boolean forceShutdown(Service service) {
+ public boolean isForceShutdown() {
return forceShutdown;
}
@@ -714,7 +714,7 @@ public class DefaultShutdownStrategy extends ServiceSupport implements ShutdownS
Consumer consumer = deferred.getConsumer();
if (consumer instanceof ShutdownAware) {
LOG.trace("Route: {} preparing to shutdown.", deferred.getRoute().getId());
- boolean forced = context.getShutdownStrategy().forceShutdown(consumer);
+ boolean forced = context.getShutdownStrategy().isForceShutdown();
boolean suppress = context.getShutdownStrategy().isSuppressLoggingOnTimeout();
prepareShutdown(consumer, suspendOnly, forced, false, suppress);
LOG.debug("Route: {} preparing to shutdown complete.", deferred.getRoute().getId());
@@ -748,7 +748,7 @@ public class DefaultShutdownStrategy extends ServiceSupport implements ShutdownS
// now the route consumers has been shutdown, then prepare route services for shutdown
for (RouteStartupOrder order : routes) {
for (Service service : order.getServices()) {
- boolean forced = context.getShutdownStrategy().forceShutdown(service);
+ boolean forced = context.getShutdownStrategy().isForceShutdown();
boolean suppress = context.getShutdownStrategy().isSuppressLoggingOnTimeout();
prepareShutdown(service, suspendOnly, forced, true, suppress);
}
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/SharedCamelInternalProcessor.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/SharedCamelInternalProcessor.java
index 449c1ac..36feec7 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/SharedCamelInternalProcessor.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/SharedCamelInternalProcessor.java
@@ -28,7 +28,6 @@ import org.apache.camel.Exchange;
import org.apache.camel.ExtendedCamelContext;
import org.apache.camel.Ordered;
import org.apache.camel.Processor;
-import org.apache.camel.Service;
import org.apache.camel.spi.AsyncProcessorAwaitManager;
import org.apache.camel.spi.CamelInternalProcessorAdvice;
import org.apache.camel.spi.ReactiveExecutor;
@@ -304,18 +303,14 @@ public class SharedCamelInternalProcessor implements SharedInternalProcessor {
return false;
}
- // determine if we can still run, or the camel context is forcing a shutdown
- if (processor instanceof Service) {
- boolean forceShutdown = shutdownStrategy.forceShutdown((Service) processor);
- if (forceShutdown) {
- String msg = "Run not allowed as ShutdownStrategy is forcing shutting down, will reject executing exchange: "
- + exchange;
- LOG.debug(msg);
- if (exchange.getException() == null) {
- exchange.setException(new RejectedExecutionException(msg));
- }
- return false;
+ if (shutdownStrategy.isForceShutdown()) {
+ String msg = "Run not allowed as ShutdownStrategy is forcing shutting down, will reject executing exchange: "
+ + exchange;
+ LOG.debug(msg);
+ if (exchange.getException() == null) {
+ exchange.setException(new RejectedExecutionException(msg));
}
+ return false;
}
// yes we can continue
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/Throttler.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/Throttler.java
index de928c8..2d4214e 100644
--- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/Throttler.java
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/Throttler.java
@@ -195,7 +195,7 @@ public class Throttler extends AsyncProcessorSupport implements Traceable, IdAwa
} catch (final InterruptedException e) {
// determine if we can still run, or the camel context is forcing a shutdown
- boolean forceShutdown = exchange.getContext().getShutdownStrategy().forceShutdown(this);
+ boolean forceShutdown = exchange.getContext().getShutdownStrategy().isForceShutdown();
if (forceShutdown) {
String msg = "Run not allowed as ShutdownStrategy is forcing shutting down, will reject executing exchange: "
+ exchange;
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
index a3b1e4c..25b4379 100644
--- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
@@ -387,8 +387,7 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport
public void run() {
// can we still run
boolean run = true;
- boolean forceShutdown = shutdownStrategy.forceShutdown(RedeliveryErrorHandler.this);
- if (forceShutdown) {
+ if (shutdownStrategy.isForceShutdown()) {
run = false;
}
if (run && isStoppingOrStopped()) {
@@ -792,8 +791,7 @@ public abstract class RedeliveryErrorHandler extends ErrorHandlerSupport
protected boolean isRunAllowed() {
// if camel context is forcing a shutdown then do not allow running
- boolean forceShutdown = shutdownStrategy.forceShutdown(RedeliveryErrorHandler.this);
- if (forceShutdown) {
+ if (shutdownStrategy.isForceShutdown()) {
return false;
}
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.java
index 64a1ace..b562309 100644
--- a/core/camel-core-processor/src/main/java/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.java
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.java
@@ -156,7 +156,7 @@ public class FailOverLoadBalancer extends LoadBalancerSupport implements Traceab
@Override
public boolean isRunAllowed() {
// determine if we can still run, or the camel context is forcing a shutdown
- boolean forceShutdown = camelContext.getShutdownStrategy().forceShutdown(this);
+ boolean forceShutdown = camelContext.getShutdownStrategy().isForceShutdown();
if (forceShutdown) {
LOG.trace("Run not allowed as ShutdownStrategy is forcing shutting down");
}