openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1819974 - /openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/runner/Cli.java
Date Wed, 03 Jan 2018 13:55:00 GMT
Author: rmannibucau
Date: Wed Jan  3 13:55:00 2018
New Revision: 1819974

URL: http://svn.apache.org/viewvc?rev=1819974&view=rev
Log:
MEECROWAVE-89 ensure Cli is AutoCloseable as well

Modified:
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/runner/Cli.java

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/runner/Cli.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/runner/Cli.java?rev=1819974&r1=1819973&r2=1819974&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/runner/Cli.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/runner/Cli.java
Wed Jan  3 13:55:00 2018
@@ -18,7 +18,9 @@
  */
 package org.apache.meecrowave.runner;
 
+import org.apache.catalina.Server;
 import org.apache.catalina.connector.Connector;
+import org.apache.catalina.core.StandardServer;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
 import org.apache.commons.cli.DefaultParser;
@@ -47,8 +49,10 @@ import static java.util.stream.Collector
 import static java.util.stream.Collectors.toMap;
 
 @Vetoed
-public class Cli implements Runnable {
+public class Cli implements Runnable, AutoCloseable {
     private final String[] args;
+    private volatile Meecrowave instance;
+    private volatile boolean closed;
 
     public Cli(final String[] args) {
         this.args = args;
@@ -63,6 +67,13 @@ public class Cli implements Runnable {
         final Meecrowave.Builder builder = parsedCommand.getBuilder();
         final CommandLine line = parsedCommand.getLine();
         try (final Meecrowave meecrowave = new Meecrowave(builder)) {
+            synchronized (this) {
+                if (closed) {
+                    return;
+                }
+                this.instance = meecrowave;
+            }
+
             final String ctx = line.getOptionValue("context", "");
             final String fixedCtx = !ctx.isEmpty() && !ctx.startsWith("/") ? '/'
+ ctx : ctx;
             final String war = line.getOptionValue("webapp");
@@ -80,6 +91,20 @@ public class Cli implements Runnable {
         meecrowave.getTomcat().getServer().await();
     }
 
+    @Override
+    public synchronized void close() {
+        if (closed) {
+            return;
+        }
+        this.closed = true;
+        if (instance != null) {
+            final Server server = instance.getTomcat().getServer();
+            if (StandardServer.class.isInstance(server)) {
+                StandardServer.class.cast(server).stopAwait();
+            }
+        }
+    }
+
     public static void main(final String[] args) {
         new Cli(args).run();
     }



Mime
View raw message