Commits

Anonymous committed 412542f

Rolling back name change in order to ensure backwards
compatibility.

Comments (0)

Files changed (13)

src/core/java/com/opensymphony/oscache/base/Cache.java

             // Update the entry's state in the map
             cacheMap.put(key, entry);
         }
+
         // Trigger an ENTRY_FLUSHED event. [CACHE-107] Do this for all flushes.
         CacheEntryEvent event = new CacheEntryEvent(this, entry, origin);
         dispatchCacheEntryEvent(CacheEntryEventType.ENTRY_FLUSHED, event);

src/core/java/com/opensymphony/oscache/web/ServletCacheAdministrator.java

 
     /**
     * Key used to store the current scope in the configuration. This is a hack
-    * to let the scope information get passed through to the BasicDiskPersistenceListener,
+    * to let the scope information get passed through to the DiskPersistenceListener,
     * and will be removed in a future release.
     */
     public final static String HASH_KEY_SCOPE = "scope";
 
     /**
     * Key used to store the current session ID in the configuration. This is a hack
-    * to let the scope information get passed through to the BasicDiskPersistenceListener,
+    * to let the scope information get passed through to the DiskPersistenceListener,
     * and will be removed in a future release.
     */
     public final static String HASH_KEY_SESSION_ID = "sessionId";
     /**
     * Key used to store the servlet container temporary directory in the configuration.
     * This is a hack to let the scope information get passed through to the
-    * BasicDiskPersistenceListener, and will be removed in a future release.
+    * DiskPersistenceListener, and will be removed in a future release.
     */
     public final static String HASH_KEY_CONTEXT_TMPDIR = "context.tempdir";
 
         // TODO - Fix me please!
         // Hack! This is nasty - if two sessions are created within a short
         // space of time it is possible they will end up with duplicate
-        // session IDs being passed to the BasicDiskPersistenceListener!...
+        // session IDs being passed to the DiskPersistenceListener!...
         config.set(HASH_KEY_SCOPE, "" + scope);
         config.set(HASH_KEY_SESSION_ID, sessionId);
 

src/core/test/com/opensymphony/oscache/base/algorithm/TestQueueCache.java

 
 import com.opensymphony.oscache.base.Config;
 import com.opensymphony.oscache.base.persistence.PersistenceListener;
-import com.opensymphony.oscache.plugins.diskpersistence.BasicDiskPersistenceListener;
-import com.opensymphony.oscache.plugins.diskpersistence.TestBasicDiskPersistenceListener;
+import com.opensymphony.oscache.plugins.diskpersistence.DiskPersistenceListener;
+import com.opensymphony.oscache.plugins.diskpersistence.TestDiskPersistenceListener;
 
 import java.util.Iterator;
 import java.util.Properties;
      */
     public void testPutOverflow() {
         // Create a listener
-        PersistenceListener listener = new BasicDiskPersistenceListener();
+        PersistenceListener listener = new DiskPersistenceListener();
 
         Properties p = new Properties();
-        p.setProperty("cache.path", TestBasicDiskPersistenceListener.CACHEDIR);
+        p.setProperty("cache.path", TestDiskPersistenceListener.CACHEDIR);
         p.setProperty("cache.memory", "true");
         p.setProperty("cache.persistence.overflow.only", "true");
-        p.setProperty("cache.persistence.class", "com.opensymphony.oscache.plugins.diskpersistence.BasicDiskPersistenceListener");
+        p.setProperty("cache.persistence.class", "com.opensymphony.oscache.plugins.diskpersistence.DiskPersistenceListener");
         listener.configure(new Config(p));
         getCache().setPersistenceListener(listener);
         getCache().clear();

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

     }
 
     /**
-    * Initialises this <tt>BasicDiskPersistenceListener</tt> using the supplied
+    * Initialises this <tt>DiskPersistenceListener</tt> using the supplied
     * configuration.
     *
     * @param config The OSCache configuration

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

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.oscache.plugins.diskpersistence;
-
-import com.opensymphony.oscache.base.Config;
-import com.opensymphony.oscache.base.persistence.CachePersistenceException;
-import com.opensymphony.oscache.base.persistence.PersistenceListener;
-import com.opensymphony.oscache.web.ServletCacheAdministrator;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.io.*;
-
-import java.util.Set;
-
-import javax.servlet.jsp.PageContext;
-
-/**
- * Persist the cache data to disk.
- *
- * The code in this class is totally not thread safe it is the resonsibility
- * of the cache using this persistence listener to handle the concurrency.
- *
- * @version        $Revision$
- * @author <a href="mailto:fbeauregard@pyxis-tech.com">Francois Beauregard</a>
- * @author <a href="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
- * @author <a href="&#109;a&#105;&#108;&#116;&#111;:chris&#64;swebtec.&#99;&#111;&#109;">Chris Miller</a>
- */
-public class BasicDiskPersistenceListener extends AbstractDiskPersistenceListener {
-    /**
-    * Build cache file name for the specified cache entry key.
-    *
-    * @param key   Cache Entry Key.
-    * @return char[] file name.
-    */
-    protected char[] getCacheFileName(String key) {
-        if ((key == null) || (key.length() == 0)) {
-            throw new IllegalArgumentException("Invalid key '" + key + "' specified to getCacheFile.");
-        }
-
-        char[] chars = key.toCharArray();
-        char[] fileChars = new char[chars.length];
-
-        for (int i = 0; i < chars.length; i++) {
-            char c = chars[i];
-
-            switch (c) {
-                case '.':
-                case '/':
-                case '\\':
-                case ' ':
-                case ':':
-                case ';':
-                case '"':
-                case '\'':
-                    fileChars[i] = '_';
-                    break;
-                default:
-                    fileChars[i] = c;
-            }
-        }
-
-        return fileChars;
-    }
-}

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

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.oscache.plugins.diskpersistence;
+
+import com.opensymphony.oscache.base.Config;
+import com.opensymphony.oscache.base.persistence.CachePersistenceException;
+import com.opensymphony.oscache.base.persistence.PersistenceListener;
+import com.opensymphony.oscache.web.ServletCacheAdministrator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.*;
+
+import java.util.Set;
+
+import javax.servlet.jsp.PageContext;
+
+/**
+ * Persist the cache data to disk.
+ *
+ * The code in this class is totally not thread safe it is the resonsibility
+ * of the cache using this persistence listener to handle the concurrency.
+ *
+ * @version        $Revision$
+ * @author <a href="mailto:fbeauregard@pyxis-tech.com">Francois Beauregard</a>
+ * @author <a href="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
+ * @author <a href="&#109;a&#105;&#108;&#116;&#111;:chris&#64;swebtec.&#99;&#111;&#109;">Chris Miller</a>
+ */
+public class DiskPersistenceListener extends AbstractDiskPersistenceListener {
+    /**
+    * Build cache file name for the specified cache entry key.
+    *
+    * @param key   Cache Entry Key.
+    * @return char[] file name.
+    */
+    protected char[] getCacheFileName(String key) {
+        if ((key == null) || (key.length() == 0)) {
+            throw new IllegalArgumentException("Invalid key '" + key + "' specified to getCacheFile.");
+        }
+
+        char[] chars = key.toCharArray();
+        char[] fileChars = new char[chars.length];
+
+        for (int i = 0; i < chars.length; i++) {
+            char c = chars[i];
+
+            switch (c) {
+                case '.':
+                case '/':
+                case '\\':
+                case ' ':
+                case ':':
+                case ';':
+                case '"':
+                case '\'':
+                    fileChars[i] = '_';
+                    break;
+                default:
+                    fileChars[i] = c;
+            }
+        }
+
+        return fileChars;
+    }
+}

src/plugins/diskpersistence/test/com/opensymphony/oscache/plugins/diskpersistence/TestBasicDiskPersistenceListener.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.oscache.plugins.diskpersistence;
-
-import com.opensymphony.oscache.base.CacheEntry;
-import com.opensymphony.oscache.base.Config;
-import com.opensymphony.oscache.base.persistence.CachePersistenceException;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import java.io.File;
-import java.io.FilenameFilter;
-
-import java.util.HashSet;
-import java.util.Properties;
-import java.util.Set;
-
-/**
- * Test all the public methods of the disk persistance listener and assert the
- * return values
- *
- * $Id$
- * @version        $Revision$
- * @author <a href="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
- */
-public final class TestBasicDiskPersistenceListener extends TestCase {
-    /**
-     * Cache dir to persist to
-     */
-    public static final String CACHEDIR = "build.test/diskcache";
-
-    /**
-     * The persistance listener used for the tests
-     */
-    private BasicDiskPersistenceListener listener = null;
-
-    /**
-     * Object content
-     */
-    private final String CONTENT = "Disk persistance content";
-
-    /**
-     * Cache group
-     */
-    private final String GROUP = "test group";
-
-    /**
-     * Object key
-     */
-    private final String KEY = "Test disk persistance listener key";
-    private CacheFileFilter cacheFileFilter = new CacheFileFilter();
-
-    public TestBasicDiskPersistenceListener(String str) {
-        super(str);
-    }
-
-    /**
-     * This methods returns the name of this test class to JUnit
-     * <p>
-     * @return The test for this class
-     */
-    public static Test suite() {
-        return new TestSuite(TestBasicDiskPersistenceListener.class);
-    }
-
-    /**
-     * This method is invoked before each testXXXX methods of the
-     * class. It set ups the variables required for each tests.
-     */
-    public void setUp() {
-        // At first invocation, create a listener
-        listener = new BasicDiskPersistenceListener();
-
-        Properties p = new Properties();
-        p.setProperty("cache.path", CACHEDIR);
-        p.setProperty("cache.memory", "false");
-        p.setProperty("cache.persistence.class", "com.opensymphony.oscache.plugins.diskpersistence.BasicDiskPersistenceListener");
-        listener.configure(new Config(p));
-    }
-
-    /**
-     * Test the cache directory removal
-     */
-    public void testClear() {
-        // Create an new element since we removed it at the last test
-        testStoreRetrieve();
-
-        // Remove the directory, and assert that we have no more entry
-        try {
-            listener.clear();
-            assertTrue(!listener.isStored(KEY));
-        } catch (CachePersistenceException cpe) {
-            cpe.printStackTrace();
-            fail("Exception thrown in test clear!");
-        }
-    }
-
-    /**
-     * Test that the previouly created file exists
-     */
-    public void testIsStored() {
-        try {
-            listener.store(KEY, CONTENT);
-
-            // Retrieve the previously created file
-            assertTrue(listener.isStored(KEY));
-
-            // Check that the fake key returns false
-            assertTrue(!listener.isStored(KEY + "fake"));
-        } catch (Exception e) {
-            e.printStackTrace();
-            fail("testIsStored raised an exception");
-        }
-    }
-
-    /**
-     * Test the cache removal
-     */
-    public void testRemove() {
-        // Create an entry if it doesn't exists
-        try {
-            if (!listener.isStored(KEY)) {
-                listener.store(KEY, CONTENT);
-            }
-
-            // Remove the previously created file
-            listener.remove(KEY);
-        } catch (CachePersistenceException cpe) {
-            cpe.printStackTrace();
-            fail("Exception thrown in test remove!");
-        }
-    }
-
-    /**
-     * Test the disk store and retrieve
-     */
-    public void testStoreRetrieve() {
-        // Create a cache entry and store it
-        CacheEntry entry = new CacheEntry(KEY);
-        entry.setContent(CONTENT);
-
-        try {
-            listener.store(KEY, entry);
-
-            // Retrieve our entry and validate the values
-            CacheEntry newEntry = (CacheEntry) listener.retrieve(KEY);
-            assertTrue(entry.getContent().equals(newEntry.getContent()));
-            assertEquals(entry.getCreated(), newEntry.getCreated());
-            assertTrue(entry.getKey().equals(newEntry.getKey()));
-
-            // Try to retrieve a non-existent object
-            assertNull(listener.retrieve("doesn't exist"));
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            fail("Exception raised!");
-        }
-    }
-
-    /**
-     * Test the storing and retrieving of groups
-     */
-    public void testStoreRetrieveGroups() {
-        // Store a group
-        Set groupSet = new HashSet();
-        groupSet.add("1");
-        groupSet.add("2");
-
-        try {
-            listener.storeGroup(GROUP, groupSet);
-
-            // Retrieve it and validate its contents
-            groupSet = listener.retrieveGroup(GROUP);
-            assertNotNull(groupSet);
-
-            assertTrue(groupSet.contains("1"));
-            assertTrue(groupSet.contains("2"));
-            assertFalse(groupSet.contains("3"));
-
-            // Try to retrieve a non-existent group
-            assertNull(listener.retrieveGroup("abc"));
-        } catch (Exception ex) {
-            ex.printStackTrace();
-            fail("Exception raised!");
-        }
-    }
-
-    protected void tearDown() throws Exception {
-        listener.clear();
-        assertTrue("Cache not cleared", new File(CACHEDIR).list(cacheFileFilter).length == 0);
-    }
-
-    private static class CacheFileFilter implements FilenameFilter {
-        public boolean accept(File dir, String name) {
-            return !"__groups__".equals(name);
-        }
-    }
-}

src/plugins/diskpersistence/test/com/opensymphony/oscache/plugins/diskpersistence/TestDiskPersistenceListener.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.oscache.plugins.diskpersistence;
+
+import com.opensymphony.oscache.base.CacheEntry;
+import com.opensymphony.oscache.base.Config;
+import com.opensymphony.oscache.base.persistence.CachePersistenceException;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import java.io.File;
+import java.io.FilenameFilter;
+
+import java.util.HashSet;
+import java.util.Properties;
+import java.util.Set;
+
+/**
+ * Test all the public methods of the disk persistance listener and assert the
+ * return values
+ *
+ * $Id$
+ * @version        $Revision$
+ * @author <a href="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
+ */
+public final class TestDiskPersistenceListener extends TestCase {
+    /**
+     * Cache dir to persist to
+     */
+    public static final String CACHEDIR = "build.test/diskcache";
+
+    /**
+     * The persistance listener used for the tests
+     */
+    private DiskPersistenceListener listener = null;
+
+    /**
+     * Object content
+     */
+    private final String CONTENT = "Disk persistance content";
+
+    /**
+     * Cache group
+     */
+    private final String GROUP = "test group";
+
+    /**
+     * Object key
+     */
+    private final String KEY = "Test disk persistance listener key";
+    private CacheFileFilter cacheFileFilter = new CacheFileFilter();
+
+    public TestDiskPersistenceListener(String str) {
+        super(str);
+    }
+
+    /**
+     * This methods returns the name of this test class to JUnit
+     * <p>
+     * @return The test for this class
+     */
+    public static Test suite() {
+        return new TestSuite(TestDiskPersistenceListener.class);
+    }
+
+    /**
+     * This method is invoked before each testXXXX methods of the
+     * class. It set ups the variables required for each tests.
+     */
+    public void setUp() {
+        // At first invocation, create a listener
+        listener = new DiskPersistenceListener();
+
+        Properties p = new Properties();
+        p.setProperty("cache.path", CACHEDIR);
+        p.setProperty("cache.memory", "false");
+        p.setProperty("cache.persistence.class", "com.opensymphony.oscache.plugins.diskpersistence.DiskPersistenceListener");
+        listener.configure(new Config(p));
+    }
+
+    /**
+     * Test the cache directory removal
+     */
+    public void testClear() {
+        // Create an new element since we removed it at the last test
+        testStoreRetrieve();
+
+        // Remove the directory, and assert that we have no more entry
+        try {
+            listener.clear();
+            assertTrue(!listener.isStored(KEY));
+        } catch (CachePersistenceException cpe) {
+            cpe.printStackTrace();
+            fail("Exception thrown in test clear!");
+        }
+    }
+
+    /**
+     * Test that the previouly created file exists
+     */
+    public void testIsStored() {
+        try {
+            listener.store(KEY, CONTENT);
+
+            // Retrieve the previously created file
+            assertTrue(listener.isStored(KEY));
+
+            // Check that the fake key returns false
+            assertTrue(!listener.isStored(KEY + "fake"));
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("testIsStored raised an exception");
+        }
+    }
+
+    /**
+     * Test the cache removal
+     */
+    public void testRemove() {
+        // Create an entry if it doesn't exists
+        try {
+            if (!listener.isStored(KEY)) {
+                listener.store(KEY, CONTENT);
+            }
+
+            // Remove the previously created file
+            listener.remove(KEY);
+        } catch (CachePersistenceException cpe) {
+            cpe.printStackTrace();
+            fail("Exception thrown in test remove!");
+        }
+    }
+
+    /**
+     * Test the disk store and retrieve
+     */
+    public void testStoreRetrieve() {
+        // Create a cache entry and store it
+        CacheEntry entry = new CacheEntry(KEY);
+        entry.setContent(CONTENT);
+
+        try {
+            listener.store(KEY, entry);
+
+            // Retrieve our entry and validate the values
+            CacheEntry newEntry = (CacheEntry) listener.retrieve(KEY);
+            assertTrue(entry.getContent().equals(newEntry.getContent()));
+            assertEquals(entry.getCreated(), newEntry.getCreated());
+            assertTrue(entry.getKey().equals(newEntry.getKey()));
+
+            // Try to retrieve a non-existent object
+            assertNull(listener.retrieve("doesn't exist"));
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            fail("Exception raised!");
+        }
+    }
+
+    /**
+     * Test the storing and retrieving of groups
+     */
+    public void testStoreRetrieveGroups() {
+        // Store a group
+        Set groupSet = new HashSet();
+        groupSet.add("1");
+        groupSet.add("2");
+
+        try {
+            listener.storeGroup(GROUP, groupSet);
+
+            // Retrieve it and validate its contents
+            groupSet = listener.retrieveGroup(GROUP);
+            assertNotNull(groupSet);
+
+            assertTrue(groupSet.contains("1"));
+            assertTrue(groupSet.contains("2"));
+            assertFalse(groupSet.contains("3"));
+
+            // Try to retrieve a non-existent group
+            assertNull(listener.retrieveGroup("abc"));
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            fail("Exception raised!");
+        }
+    }
+
+    protected void tearDown() throws Exception {
+        listener.clear();
+        assertTrue("Cache not cleared", new File(CACHEDIR).list(cacheFileFilter).length == 0);
+    }
+
+    private static class CacheFileFilter implements FilenameFilter {
+        public boolean accept(File dir, String name) {
+            return !"__groups__".equals(name);
+        }
+    }
+}

src/plugins/diskpersistence/test/com/opensymphony/oscache/plugins/diskpersistence/TestHashDiskPersistenceListener.java

         listener = new HashDiskPersistenceListener();
 
         Properties p = new Properties();
-        p.setProperty("cache.path", TestBasicDiskPersistenceListener.CACHEDIR);
+        p.setProperty("cache.path", TestDiskPersistenceListener.CACHEDIR);
         p.setProperty("cache.memory", "false");
         p.setProperty("cache.persistence.class", "com.opensymphony.oscache.plugins.diskpersistence.HashDiskPersistenceListener");
         p.setProperty("cache.persistence.disk.hash.algorithm", "MD5");
 
     protected void tearDown() throws Exception {
         listener.clear();
-        assertTrue("Cache not cleared", new File(TestBasicDiskPersistenceListener.CACHEDIR).list(cacheFileFilter).length == 0);
+        assertTrue("Cache not cleared", new File(TestDiskPersistenceListener.CACHEDIR).list(cacheFileFilter).length == 0);
     }
 
     private static class CacheFileFilter implements FilenameFilter {

src/plugins/diskpersistence/test/oscacheDiskAndMemory.properties

 cache.capacity=100
 
 # CACHE PERSISTENCE CLASS
-cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.BasicDiskPersistenceListener
+cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.DiskPersistenceListener
 
 # CACHE DIRECTORY
 cache.path=/tmp/cachetagscache

src/plugins/diskpersistence/test/oscacheDiskOnly.properties

 cache.memory=false
 
 # CACHE PERSISTENCE CLASS
-cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.BasicDiskPersistenceListener
+cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.DiskPersistenceListener
 
 # CACHE DIRECTORY
 cache.path=/tmp/cachetagscache

src/plugins/diskpersistence/test/oscacheMemoryAndOverflowToDisk.properties

 cache.memory=true
 
 # CACHE PERSISTENCE CLASS
-cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.BasicDiskPersistenceListener
+cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.DiskPersistenceListener
 
 # CACHE DIRECTORY
 cache.path=/tmp/cachetagscache

src/webapp/WEB-INF/classes/oscache.properties

 # 
 # If a persistence class is not specified, OSCache will use memory caching only.
 #
-# cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.BasicDiskPersistenceListener
+# cache.persistence.class=com.opensymphony.oscache.plugins.diskpersistence.DiskPersistenceListener
 
 # CACHE OVERFLOW PERSISTENCE
 # Use persistent cache in overflow or not. The default value is false, which means