activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [2/2] activemq-artemis git commit: ARTEMIS-958 Improve web server tmp dir cleanup
Date Wed, 15 Feb 2017 01:18:55 GMT
ARTEMIS-958 Improve web server tmp dir cleanup

When server is shutdown by user the shutdown hook will check
if the tmpdir of the web server is cleaned up. However the cleanup
is also performed in a shutdown hook (using File.deleteOnExit).
Because the order of execution of hooks is not guaranteed,
if the tmp dir is not cleaned up by the time of check,
we should add a 'force' delete to make sure the tmp dir
is removed after server stop.


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/f6670c9a
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/f6670c9a
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/f6670c9a

Branch: refs/heads/master
Commit: f6670c9aafd6fd2cde7513225ae04cd80891929d
Parents: 8938c26
Author: Howard Gao <howard.gao@gmail.com>
Authored: Tue Feb 14 09:34:06 2017 +0800
Committer: Clebert Suconic <clebertsuconic@apache.org>
Committed: Tue Feb 14 20:17:23 2017 -0500

----------------------------------------------------------------------
 .../artemis/component/WebServerComponent.java        | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/f6670c9a/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java
----------------------------------------------------------------------
diff --git a/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java
b/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java
index c58bafb..a6df272 100644
--- a/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java
+++ b/artemis-web/src/main/java/org/apache/activemq/artemis/component/WebServerComponent.java
@@ -29,6 +29,7 @@ import org.apache.activemq.artemis.components.ExternalComponent;
 import org.apache.activemq.artemis.dto.AppDTO;
 import org.apache.activemq.artemis.dto.ComponentDTO;
 import org.apache.activemq.artemis.dto.WebServerDTO;
+import org.apache.activemq.artemis.utils.FileUtil;
 import org.apache.activemq.artemis.utils.TimeUtils;
 import org.eclipse.jetty.server.Connector;
 import org.eclipse.jetty.server.HttpConfiguration;
@@ -43,9 +44,12 @@ import org.eclipse.jetty.server.handler.HandlerList;
 import org.eclipse.jetty.server.handler.ResourceHandler;
 import org.eclipse.jetty.util.ssl.SslContextFactory;
 import org.eclipse.jetty.webapp.WebAppContext;
+import org.jboss.logging.Logger;
 
 public class WebServerComponent implements ExternalComponent {
 
+   private static final Logger logger = Logger.getLogger(WebServerComponent.class);
+
    private Server server;
    private HandlerList handlers;
    private WebServerDTO webServerConfig;
@@ -145,9 +149,16 @@ public class WebServerComponent implements ExternalComponent {
                //tmpdir will be removed by deleteOnExit()
                //somehow when broker is stopped and restarted quickly
                //this tmpdir won't get deleted sometimes
-               boolean fileDeleted = TimeUtils.waitOnBoolean(false, 10000, tmpdir::exists);
+               boolean fileDeleted = TimeUtils.waitOnBoolean(false, 5000, tmpdir::exists);
                if (!fileDeleted) {
-                  ActiveMQWebLogger.LOGGER.tmpFileNotDeleted(tmpdir);
+                  //because the execution order of shutdown hooks are
+                  //not determined, so it's possible that the deleteOnExit
+                  //is executed after this hook, in that case we force a delete.
+                  FileUtil.deleteDirectory(tmpdir);
+                  logger.debug("Force to delete temporary file on shutdown: " + tmpdir.getAbsolutePath());
+                  if (tmpdir.exists()) {
+                     ActiveMQWebLogger.LOGGER.tmpFileNotDeleted(tmpdir);
+                  }
                }
             }
          }


Mime
View raw message