geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ke...@apache.org
Subject svn commit: r356407 - in /geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment: Deployer.java util/DeploymentUtil.java
Date Mon, 12 Dec 2005 23:00:38 GMT
Author: kevan
Date: Mon Dec 12 15:00:35 2005
New Revision: 356407

URL: http://svn.apache.org/viewcvs?rev=356407&view=rev
Log:
Does a better job of cleaning up temporary deployment files. Doesn't get all files. Also,
implementation could be better, but want to get this in. I'll improve as time permits...

Modified:
    geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java
    geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/DeploymentUtil.java

Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java?rev=356407&r1=356406&r2=356407&view=diff
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java
(original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java
Mon Dec 12 15:00:35 2005
@@ -40,11 +40,13 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 import java.util.jar.Attributes;
 import java.util.jar.JarFile;
@@ -57,6 +59,9 @@
  */
 public class Deployer {
     private static final Log log = LogFactory.getLog(Deployer.class);
+    private final int REAPER_INTERVAL = 60 * 1000;
+    private final Properties pendingDeletionIndex = new Properties();
+    private DeployerReaper reaper;
     private final Collection builders;
     private final ConfigurationStore store;
     private final Kernel kernel;
@@ -65,6 +70,12 @@
         this.builders = builders;
         this.store = store;
         this.kernel = kernel;
+
+        // Create and start the reaper...
+        this.reaper = new DeployerReaper(REAPER_INTERVAL);
+        Thread t = new Thread(reaper, "Geronimo Config Store Reaper");
+        t.setDaemon(true);
+        t.start();
     }
 
     public List deploy(File moduleFile, File planFile) throws DeploymentException {
@@ -73,10 +84,10 @@
         if (moduleFile != null && !moduleFile.isDirectory()) {
             // todo jar url handling with Sun's VM on Windows leaves a lock on the module
file preventing rebuilds
             // to address this we use a gross hack and copy the file to a temporary directory
-            // unfortunately the lock on the file will prevent that being deleted properly
-            // we need to rewrite deployment so that it does not use jar: urls
+            // the lock on the file will prevent that being deleted properly until the URLJarFile
has 
+            // been GC'ed.
             try {
-                tmpDir = File.createTempFile("deployer", ".tmpdir");
+                tmpDir = File.createTempFile("geronimo-deployer", ".tmpdir");
                 tmpDir.delete();
                 tmpDir.mkdir();
                 File tmpFile = new File(tmpDir, moduleFile.getName());
@@ -94,7 +105,9 @@
             throw e.cleanse();
         } finally {
             if (tmpDir != null) {
-                DeploymentUtil.recursiveDelete(tmpDir);
+                if (!DeploymentUtil.recursiveDelete(tmpDir)) {
+                    pendingDeletionIndex.setProperty(tmpDir.getName(), new String("delete"));
+                }
             }
         }
     }
@@ -270,7 +283,10 @@
                     }
                     return deployedURIs;
                 } else {
-                    DeploymentUtil.recursiveDelete(configurationDir);
+                    if (!DeploymentUtil.recursiveDelete(configurationDir)) {
+                        pendingDeletionIndex.setProperty(configurationDir.getName(), new
String("delete"));
+                        log.debug("Queued deployment directory to be reaped " + configurationDir);
                       
+                    }
                     return Collections.EMPTY_LIST;
                 }
             } catch (InvalidConfigException e) {
@@ -278,7 +294,10 @@
                 throw new DeploymentException(e);
             }
         } catch(Throwable e) {
-            DeploymentUtil.recursiveDelete(configurationDir);
+            if (!DeploymentUtil.recursiveDelete(configurationDir)) {
+                pendingDeletionIndex.setProperty(configurationDir.getName(), new String("delete"));
+                log.debug("Queued deployment directory to be reaped " + configurationDir);
                       
+            }
             if (targetFile != null) {
                 targetFile.delete();
             }
@@ -298,6 +317,57 @@
         }
     }
 
+    /**
+     * Thread to cleanup unused temporary Deployer directories (and files).
+     * On Windows, open files can't be deleted. Until MultiParentClassLoaders
+     * are GC'ed, we won't be able to delete Config Store directories/files.
+     */
+    class DeployerReaper implements Runnable {
+        private final int reaperInterval;
+        private volatile boolean done = false;
+
+        public DeployerReaper(int reaperInterval) {
+            this.reaperInterval = reaperInterval;
+        }
+
+        public void close() {
+            this.done = true;
+        }
+
+        public void run() {
+            log.debug("ConfigStoreReaper started");
+            while(!done) {
+                try {
+                    Thread.sleep(reaperInterval);
+                } catch (InterruptedException e) {
+                    continue;
+                }
+                reap();
+            }
+        }
+
+        /**
+         * For every directory in the pendingDeletionIndex, attempt to delete all 
+         * sub-directories and files.
+         */
+        public void reap() {
+            // return, if there's nothing to do
+            if (pendingDeletionIndex.size() == 0)
+                return;
+            // Otherwise, attempt to delete all of the directories
+            Enumeration list = pendingDeletionIndex.propertyNames();
+            while (list.hasMoreElements()) {
+                String dirName = (String)list.nextElement();
+                File deleteDir = new File(dirName);
+
+                if (!DeploymentUtil.recursiveDelete(deleteDir)) {
+                    pendingDeletionIndex.remove(deleteDir);
+                    log.debug("Reaped deployment directory " + deleteDir);
+                }
+            }
+        }
+    }
+    
     public static final GBeanInfo GBEAN_INFO;
 
     private static final String DEPLOYER = "Deployer";

Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/DeploymentUtil.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/DeploymentUtil.java?rev=356407&r1=356406&r2=356407&view=diff
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/DeploymentUtil.java
(original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/DeploymentUtil.java
Mon Dec 12 15:00:35 2005
@@ -55,7 +55,7 @@
 
     // be careful to clean up the temp directory
     public static File createTempDir() throws IOException {
-        File tempDir = File.createTempFile("geronimo-deployment-", ".tmp");
+        File tempDir = File.createTempFile("geronimo-deploymentUtil", ".tmpdir");
         tempDir.delete();
         tempDir.mkdirs();
         return tempDir;
@@ -64,7 +64,7 @@
     // be careful to clean up the temp file... we tell the vm to delete this on exit
     // but VMs can't be trusted to acutally delete the file
     public static File createTempFile() throws IOException {
-        File tempFile = File.createTempFile("geronimo-deployment-", "tmp");
+        File tempFile = File.createTempFile("geronimo-deploymentUtil", ".tmpdir");
         tempFile.deleteOnExit();
         return tempFile;
     }
@@ -220,9 +220,9 @@
         }
     }
 
-    public static void recursiveDelete(File root) {
+    public static boolean recursiveDelete(File root) {
         if (root == null) {
-            return;
+            return true;
         }
 
         if (root.isDirectory()) {
@@ -238,7 +238,7 @@
                 }
             }
         }
-        root.delete();
+        return root.delete();
     }
 
     public static Collection listRecursiveFiles(File file) {



Mime
View raw message