Commits

Anonymous committed 4a1e767

CACHE-306 log exceptions with stack trace of store method of AbstractDiskPersistenceListener

Comments (0)

Files changed (7)

 # OSCache build properties
 name=oscache
 fullname=OSCache
-version=2.4.1
+version=2.4.2-dev
 status=integration
 cvs.tag=v2_4_1
 
 <?xml-stylesheet type="text/xsl" href="http://www.jayasoft.fr/org/ivyrep/ivy-doc.xsl"?>
 <ivy-module version="1.0">
     <info organisation="opensymphony" module="oscache"
-          revision="2.4.1"
-          status="release"
-          publication="20070707120000">
+          revision="2.4.2"
+          status="integration"
+          publication="20080405310000">
         <license name="Apache" url="http://www.apache.org/licenses/LICENSE-2.0.txt"/>
         <ivyauthor name="opensymphony" url="http://www.opensymphony.com/"/>
 
     <modelVersion>4.0.0</modelVersion>
     <groupId>opensymphony</groupId>
     <artifactId>oscache</artifactId>
-    <version>2.4.1</version>
+    <version>2.4.2</version>
     <name>OSCache</name>
     <description>
         OSCache is a caching solution that includes a JSP tag library

src/java/com/opensymphony/oscache/base/persistence/CachePersistenceException.java

     public CachePersistenceException(String msg) {
         super(msg);
     }
+    
+    public CachePersistenceException(String message, Throwable cause) {
+        super(message, cause);
+    }
 }

src/java/com/opensymphony/oscache/plugins/diskpersistence/AbstractDiskPersistenceListener.java

 import org.apache.commons.logging.LogFactory;
 
 import java.io.*;
-
 import java.util.Set;
 
 import javax.servlet.jsp.PageContext;
  * @author <a href="mailto:amarch@soe.sony.com">Andres March</a>
  */
 public abstract class AbstractDiskPersistenceListener implements PersistenceListener, Serializable {
+	
+    private static final Log LOG = LogFactory.getLog(AbstractDiskPersistenceListener.class);
+
     public final static String CACHE_PATH_KEY = "cache.path";
 
     /**
                 } 
             }
         } catch (Exception e) {
-            throw new CachePersistenceException("Unable to remove '" + file + "' from the cache: " + e);
+            throw new CachePersistenceException("Unable to remove file '" + file + "' from the disk cache.", e);
         }
         if (file.exists() && count == 0) {
-            throw new CachePersistenceException("Unable to delete '" + file + "' from the cache. "+DELETE_COUNT+" attempts at "+DELETE_THREAD_SLEEP+" milliseconds intervals.");
+            throw new CachePersistenceException("Unable to delete '" + file + "' from the disk cache. "+DELETE_COUNT+" attempts at "+DELETE_THREAD_SLEEP+" milliseconds intervals.");
         }
     }
 
                     filepath.mkdirs();
                 }
             } catch (Exception e) {
-                throw new CachePersistenceException("Unable to create the directory " + filepath);
+                throw new CachePersistenceException("Unable to create the directory " + filepath, e);
             }
         }
 
                     try {
                         oout.close();
                     } catch (Exception e) {
+                    	LOG.warn("Problem closing file of disk cache.", e);
                     }
                 }
             } finally {
                 try {
                     fout.close();
                 } catch (Exception e) {
+                	LOG.warn("Problem closing file of disk cache.", e);
                 }
             }
         } catch (Exception e) {
                 } catch (InterruptedException ignore) {
                 } 
             }
-            throw new CachePersistenceException("Unable to write '" + file + "' in the cache. Exception: " + e.getClass().getName() + ", Message: " + e.getMessage());
+            throw new CachePersistenceException("Unable to write file '" + file + "' in the disk cache.", e);
         }
     }
 
         try {
             fileExist = file.exists();
         } catch (Exception e) {
-            throw new CachePersistenceException("Unable to verify if " + file + " exists: " + e);
+            throw new CachePersistenceException("Unable to verify if file '" + file + "' exists.", e);
         }
 
         // Read the file if it exists
                 // This is when the item will be invalidated (written or deleted)
                 // during read.
                 // The cache has the logic to retry reading.
-                throw new CachePersistenceException("Unable to read '" + file.getAbsolutePath() + "' from the cache: " + e);
+                throw new CachePersistenceException("Unable to read file '" + file.getAbsolutePath() + "' from the disk cache.", e);
             } finally {
               // HHDE: no need to close in. Will be closed by oin
                 try {

src/java/com/opensymphony/oscache/plugins/diskpersistence/HashDiskPersistenceListener.java

 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 /**
  * Persists cache data to disk. Provides a hash of the standard key name as the file name.
  *
  */
 public class HashDiskPersistenceListener extends AbstractDiskPersistenceListener {
     
+    private static final Log LOG = LogFactory.getLog(HashDiskPersistenceListener.class);
+
     private static final int DIR_LEVELS = 3;
     
     public final static String HASH_ALGORITHM_KEY = "cache.persistence.disk.hash.algorithm";
                 md = MessageDigest.getInstance(HashDiskPersistenceListener.DEFAULT_HASH_ALGORITHM);
             }
         } catch (NoSuchAlgorithmException e) {
-            e.printStackTrace();
+        	LOG.warn("No hash algorithm available for disk persistence", e);
             throw new RuntimeException("No hash algorithm available for disk persistence", e);
         }
 

src/test/java/com/opensymphony/oscache/base/TestConcurrency.java

                     Thread inspectedThread = spawnedThreads[threadIndex];
 
                     try {
-                        inspectedThread.join(maxWaitForEachThread * 1000);
+                        inspectedThread.join(maxWaitForEachThread * 1000L);
                     } catch (InterruptedException e) {
                         fail("Thread #" + threadIndex + " was interrupted");
                     }