You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Clinton Davidson <Cl...@plumtree.com> on 2005/01/20 19:40:51 UTC

Feature request- Delete orphaned temp files on startup.

The use case is to delete orphaned temp files, e.g. those that may have
been left over from abnormal VM termination. 

 

The proposed changes would be in  org.apache.axis.AxisEngine.java, with
a minor change in
org.apache.axis.attachments.ManagedMemoryDataSource.java

 

In AxisEngine:

 

Changes to imports:

 

import java.io.FilenameFilter;

import java.io.File;

 

in member variables:

 

 /** Temp file prefix used when the data is flushed to disk */

 public static final String TEMP_FILE_PREFIX = "Axis";

 /** Temp file suffix used when the data is flushed to disk */

 public static final String TEMP_FILE_SUFFIX = "axis";

 

 /** <code>true</code> if the orphaned disk cache files have been
deleted **/

 private static boolean orphanedDiskCacheFilesDeleted = false;

 

 

in init, directly before the log message to exit:

 

//only do it once

if (!orphanedDiskCacheFilesDeleted) {

    deleteOrphanedDiskCacheFiles();

    orphanedDiskCacheFilesDeleted = true;

}

 

Additional method to remove temp files:

 

     private void deleteOrphanedDiskCacheFiles()

     {

         if (log.isDebugEnabled()) {

             log.debug("Enter:
AxisEngine::deleteOrphanedDiskCacheFiles");

         }

 

         String tempDirName = (String) getOption(PROP_ATTACHMENT_DIR);

         if (tempDirName == null) {

             tempDirName = System.getProperty("java.io.tmpdir");

         }

 

         if (log.isTraceEnabled()) {

             log.trace("tempDirName: " + tempDirName);

         }

 

         File tempDir = new File(tempDirName);

         if (!tempDir.exists() || !tempDir.isDirectory())

             return;

 

         //matches our temp files

         FilenameFilter tempFileFilter = new FilenameFilter() {

             public boolean accept(File dir, String name) {

                 boolean isTempFile = name.startsWith(TEMP_FILE_PREFIX)
&& name.endsWith(TEMP_FILE_SUFFIX);

                 return isTempFile;

             }

         };

 

         File[] tempFiles = tempDir.listFiles(tempFileFilter);

         if (log.isTraceEnabled()) {

             log.trace("number of our temp files in the temp dir: " +
tempFiles.length);

         }

         for (int i = 0; i < tempFiles.length; i++) {

             File tempFile = tempFiles[i];

             if (log.isTraceEnabled()) {

                 log.trace("deleting our temp file: " +
tempFile.getName());

             }

             tempFile.delete();

         }

 

         if (log.isDebugEnabled()) {

             log.debug("Exit:
AxisEngine::deleteOrphanedDiskCacheFiles");

         }

     }

 

In ManagedMemoryDataSource:

 

Add an import for axis engine:

 

import org.apache.axis.AxisEngine;

 

 

in flushToDisk(), replace the hard coded name with the constant from
AxisEngine

 

//diskCacheFile = java.io.File.createTempFile("Axis", "axis",

diskCacheFile = java.io.File.createTempFile(AxisEngine.TEMP_FILE_PREFIX,
AxisEngine.TEMP_FILE_SUFFIX,

 

 

Let me know if this should be filed as a bug or a feature request, or if
you have any feedback about the proposed patch.

 

Thanks

 

Clinton