Anonymous avatar Anonymous committed d77a7db

Issue number: CACHE-226 CACHE-227 CACHE-136 Drop Java 1.3 support and remove commons collections from the library
Obtained from: Lars Torunski

Comments (0)

Files changed (4)

 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 	<classpathentry kind="lib" path="lib/servletapi.jar"/>
 	<classpathentry kind="lib" path="lib/clover.jar"/>
-	<classpathentry kind="lib" path="lib/commons-collections.jar"/>
 	<classpathentry kind="lib" path="lib/commons-logging.jar"/>
 	<classpathentry kind="lib" path="lib/httpunit.jar"/>
 	<classpathentry kind="lib" path="lib/jms.jar"/>
 
     <!-- Compiles the core source code -->
     <target name="compile" depends="prepare">
-        <javac srcdir="${src.java}" destdir="${build.java}" includes="com/opensymphony/oscache/**" debug="${debug}" classpathref="cp"/>
+        <javac srcdir="${src.java}" destdir="${build.java}" includes="com/opensymphony/oscache/**" debug="${debug}" classpathref="cp" source="1.4" target="1.4"/>
     </target>
 
 
 
         <war destfile="${dist}/${name}-example.war" basedir="${src.webapp}" webxml="${src.webapp}/WEB-INF/web.xml" excludes="WEB-INF/web.xml">
             <lib file="${build}/${name}-${version}.jar"/>
-            <lib file="${lib}/commons-collections.jar"/>
             <lib file="${lib}/commons-logging.jar"/>
             <classes dir="${build}/webapp"/>
         </war>
             <fileset dir="${src}" excludes="etc/**"/>
         </copy>
         
-        <copy file="${lib}/commons-collections.jar" todir="${tmp.dir}/lib"/>
         <copy file="${lib}/commons-logging.jar" todir="${tmp.dir}/lib"/>
         <copy file="${lib}/jgroups-all.jar" todir="${tmp.dir}/lib"/>
 
     <info organisation="opensymphony" module="oscache"
           revision="2.3"
           status="integration"
-          publication="20051112120000">
+          publication="20051218120000">
         <license name="Apache" url="http://www.apache.org/licenses/LICENSE-2.0.txt"/>
         <ivyauthor name="opensymphony" url="http://www.opensymphony.com/"/>
 
 
         <!-- oscache -->
         <dependency org="apache" name="commons-logging" rev="1.0.4" conf="default->*"/>
-        <dependency org="apache" name="commons-collections" rev="3.1" conf="default->*"/>
 
         <!-- jgroups -->
         <dependency org="jgroups" name="jgroups-all" rev="2.2.8" conf="jgroups->*"/>

src/java/com/opensymphony/oscache/base/algorithm/LRUCache.java

  */
 package com.opensymphony.oscache.base.algorithm;
 
-import com.opensymphony.oscache.util.ClassLoaderUtil;
-
-import org.apache.commons.collections.SequencedHashMap;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 /**
  * <p>LRU (Least Recently Used) algorithm for the cache.</p>
  *
- * <p>This class tries to provide the best possible performance by first
- * attempting to use the JDK 1.4.x <code>LinkedHashSet</code> class,
- * followed by the Jakarta commons-collections <code>SequencedHashMap</code>
- * class, and finally resorting to the <code>LinkedList</code> class if
- * neither of the above classes are available. If this class has to revert
- * to using a <code>LinkedList</code> a warning is logged since the performance
- * penalty can be severe.</p>
+ * <p>Since release 2.3 this class requires Java 1.4 
+ * to use the <code>LinkedHashSet</code>. Use prior OSCache release which
+ * require the Jakarta commons-collections <code>SequencedHashMap</code>
+ * class or the <code>LinkedList</code> class if neither of the above
+ * classes are available.</p>
  *
  * <p>No synchronization is required in this class since the
  * <code>AbstractConcurrentReadCache</code> already takes care of any
  * @author <a href="&#109;a&#105;&#108;&#116;&#111;:chris&#64;swebtec.&#99;&#111;&#109;">Chris Miller</a>
  */
 public class LRUCache extends AbstractConcurrentReadCache {
+	
     private static final Log log = LogFactory.getLog(LRUCache.class);
 
     /**
     private Collection list;
 
     /**
-     * Jakarta commons collections unfortunately doesn't provide us with an ordered
-     * hash set, so we have to use their ordered map instead.
-     */
-    private Map map;
-
-    /**
-     * A flag indicating if we are using a List for the key collection. This happens
-     * when we're running under JDK 1.3 or lower and there is no commons-collections
-     * in the classpath.
-     */
-    private boolean isList = false;
-
-    /**
-     * A flag indicating if we are using a Map for the key collection. This happens
-     * when we're running under JDK 1.3 and commons-collections is available.
-     */
-    private boolean isMap = false;
-
-    /**
-     * A flag indicating if we are using a Set for the key collection. This happens
-     * when we're running under JDK 1.4 and is the best case scenario.
-     */
-    private boolean isSet = false;
-
-    /**
      * A flag indicating whether there is a removal operation in progress.
      */
     private volatile boolean removeInProgress = false;
      */
     public LRUCache() {
         super();
-
-        // Decide if we're running under JRE 1.4+. If so we can use a LinkedHashSet
-        // instead of a LinkedList for a big performance boost when removing elements.
-        try {
-            ClassLoaderUtil.loadClass("java.util.LinkedHashSet", this.getClass());
-            list = new LinkedHashSet();
-            isSet = true;
-        } catch (ClassNotFoundException e) {
-            // There's no LinkedHashSet available so we'll try for the jakarta-collections
-            // SequencedHashMap instead [CACHE-47]
-            try {
-                ClassLoaderUtil.loadClass("org.apache.commons.collections.SequencedHashMap", this.getClass());
-                map = new SequencedHashMap();
-                isMap = true;
-            } catch (ClassNotFoundException e1) {
-                // OK, time to get all inefficient and resort to a LinkedList. We log this
-                // as a warning since it potentially can have a big impact.
-                log.warn("When using the LRUCache under JRE 1.3.x, commons-collections.jar should be added to your classpath to increase OSCache's performance.");
-                list = new LinkedList();
-                isList = true;
-            }
-        }
+        list = new LinkedHashSet();
     }
 
     /**
 
         // We need to synchronize here because AbstractConcurrentReadCache
         // doesn't prevent multiple threads from calling this method simultaneously.
-        if (isMap) {
-            synchronized (map) {
-                map.remove(key);
-                map.put(key, Boolean.TRUE);
-            }
-        } else {
-            synchronized (list) {
-                list.remove(key);
-                list.add(key);
-            }
+        synchronized (list) {
+            list.remove(key);
+            list.add(key);
         }
     }
 
      */
     protected void itemPut(Object key) {
         // Since this entry was just accessed, move it to the back of the list.
-        if (isMap) {
-            synchronized (map) { // A further fix for CACHE-44
-                map.remove(key);
-                map.put(key, Boolean.TRUE);
-            }
-        } else {
-            synchronized (list) { // A further fix for CACHE-44
-                list.remove(key);
-                list.add(key);
-            }
+    	synchronized (list) { // A further fix for CACHE-44
+    		list.remove(key);
+            list.add(key);
         }
     }
 
                     Thread.sleep(5);
                 } catch (InterruptedException ie) {
                 }
-            } while (isMap ? (map.size() == 0) : (list.size() == 0));
+            } while (list.size() == 0);
 
             toRemove = removeFirst();
         }
      * @param key The cache key of the item that was removed.
      */
     protected void itemRemoved(Object key) {
-        if (isMap) {
-            map.remove(key);
-        } else {
-            list.remove(key);
-        }
+        list.remove(key);
     }
 
     /**
      * @return the object that was removed
      */
     private Object removeFirst() {
-        Object toRemove;
-
-        if (isSet) {
-            Iterator it = list.iterator();
-            toRemove = it.next();
-            it.remove();
-        } else if (isMap) {
-            toRemove = ((SequencedHashMap) map).getFirstKey();
-            map.remove(toRemove);
-        } else {
-            toRemove = ((List) list).remove(0);
-        }
+        Iterator it = list.iterator();
+        Object toRemove = it.next();
+        it.remove();
 
         return toRemove;
     }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.