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

lburgazzoli pushed a commit to branch 1.0.x
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 6db3edeecb027d5dc26175c22de7d6034803c7b5
Author: lburgazzoli <lburgazz...@gmail.com>
AuthorDate: Wed Aug 12 13:30:41 2020 +0200

    Upgarde to camel v3.4.3 (fix MainShutdownStrategy)
---
 .../org/apache/camel/quarkus/main/CamelMain.java   | 53 ++--------------------
 1 file changed, 5 insertions(+), 48 deletions(-)

diff --git 
a/extensions-core/main/runtime/src/main/java/org/apache/camel/quarkus/main/CamelMain.java
 
b/extensions-core/main/runtime/src/main/java/org/apache/camel/quarkus/main/CamelMain.java
index 7e71a52..ab75ad5 100644
--- 
a/extensions-core/main/runtime/src/main/java/org/apache/camel/quarkus/main/CamelMain.java
+++ 
b/extensions-core/main/runtime/src/main/java/org/apache/camel/quarkus/main/CamelMain.java
@@ -18,8 +18,6 @@ package org.apache.camel.quarkus.main;
 
 import java.util.Collection;
 import java.util.Collections;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import io.quarkus.runtime.Quarkus;
@@ -31,6 +29,7 @@ import org.apache.camel.main.MainCommandLineSupport;
 import org.apache.camel.main.MainConfigurationProperties;
 import org.apache.camel.main.MainListener;
 import org.apache.camel.main.MainShutdownStrategy;
+import org.apache.camel.main.SimpleMainShutdownStrategy;
 import org.apache.camel.spi.CamelBeanPostProcessor;
 import org.apache.camel.spi.HasCamelContext;
 import org.apache.camel.support.service.ServiceHelper;
@@ -59,7 +58,10 @@ public final class CamelMain extends MainCommandLineSupport 
implements HasCamelC
 
     @Override
     protected void doInit() throws Exception {
-        setShutdownStrategy(new ShutdownStrategy());
+        MainShutdownStrategy shutdownStrategy = new 
SimpleMainShutdownStrategy();
+        shutdownStrategy.addShutdownListener(() -> 
Quarkus.asyncExit(getExitCode()));
+
+        setShutdownStrategy(shutdownStrategy);
 
         super.doInit();
         initCamelContext();
@@ -148,49 +150,4 @@ public final class CamelMain extends 
MainCommandLineSupport implements HasCamelC
         parseArguments(args);
         runEngine();
     }
-
-    /**
-     * Implementation of a {@link MainShutdownStrategy} based on Quarkus 
Command Mode.
-     *
-     * @see <a href="https://quarkus.io/guides/command-mode-reference";>Quarkus 
Command Mode Applications</a>
-     */
-    private class ShutdownStrategy implements MainShutdownStrategy {
-        private final AtomicBoolean completed;
-        private final CountDownLatch latch;
-
-        public ShutdownStrategy() {
-            this.completed = new AtomicBoolean(false);
-            this.latch = new CountDownLatch(1);
-        }
-
-        @Override
-        public boolean isRunAllowed() {
-            return !completed.get();
-        }
-
-        @Override
-        public boolean shutdown() {
-            if (completed.compareAndSet(false, true)) {
-                latch.countDown();
-                Quarkus.asyncExit(getExitCode());
-                return true;
-            }
-
-            return false;
-        }
-
-        @Override
-        public void await() throws InterruptedException {
-            latch.await();
-        }
-
-        @Override
-        public void await(long timeout, TimeUnit unit) throws 
InterruptedException {
-            if (!latch.await(timeout, unit)) {
-                LOGGER.warn(
-                        "Could not await stopping CamelMain within {} {}. You 
may want to increase camel.main.shutdown.timeout",
-                        timeout, unit);
-            }
-        }
-    }
 }

Reply via email to