[jboss-cvs] JBossCache/src/org/jboss/cache/eviction ...

Elias Ross genman at noderunner.net
Tue Mar 6 14:18:19 EST 2007


  User: genman  
  Date: 07/03/06 14:18:19

  Modified:    src/org/jboss/cache/eviction       
                        BaseEvictionAlgorithm.java ElementSizeQueue.java
                        EvictionQueueList.java FIFOQueue.java LFUQueue.java
                        LRUQueue.java MRUQueue.java
  Log:
  Assign generic type arguments to collections
  
  Revision  Changes    Path
  1.23      +4 -5      JBossCache/src/org/jboss/cache/eviction/BaseEvictionAlgorithm.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: BaseEvictionAlgorithm.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/eviction/BaseEvictionAlgorithm.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -b -r1.22 -r1.23
  --- BaseEvictionAlgorithm.java	8 Feb 2007 17:07:35 -0000	1.22
  +++ BaseEvictionAlgorithm.java	6 Mar 2007 19:18:19 -0000	1.23
  @@ -23,7 +23,7 @@
    * abstract methods and a policy.
    *
    * @author Daniel Huang - dhuang at jboss.org 10/2005
  - * @version $Revision: 1.22 $
  + * @version $Revision: 1.23 $
    */
   public abstract class BaseEvictionAlgorithm implements EvictionAlgorithm
   {
  @@ -37,7 +37,7 @@
      /**
       * Contains Fqn instances.
       */
  -   protected BlockingQueue recycleQueue;
  +   protected BlockingQueue<Fqn> recycleQueue;
   
      /**
       * Contains NodeEntry instances.
  @@ -64,7 +64,7 @@
   
      protected BaseEvictionAlgorithm()
      {
  -      recycleQueue = new LinkedBlockingQueue(500000);
  +      recycleQueue = new LinkedBlockingQueue<Fqn>(500000);
      }
   
      protected void initialize(Region region) throws EvictionException
  @@ -447,7 +447,7 @@
            try
            {
               //fqn = (Fqn) recycleQueue.take();
  -            fqn = (Fqn) recycleQueue.poll(0, TimeUnit.SECONDS);
  +            fqn = recycleQueue.poll(0, TimeUnit.SECONDS);
            }
            catch (InterruptedException e)
            {
  @@ -502,7 +502,6 @@
         return false;
      }
   
  -
      protected void prune() throws EvictionException
      {
         NodeEntry entry;
  
  
  
  1.3       +20 -21    JBossCache/src/org/jboss/cache/eviction/ElementSizeQueue.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ElementSizeQueue.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/eviction/ElementSizeQueue.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- ElementSizeQueue.java	8 Jun 2006 17:37:39 -0000	1.2
  +++ ElementSizeQueue.java	6 Mar 2007 19:18:19 -0000	1.3
  @@ -21,23 +21,23 @@
   
   /**
    * @author Daniel Huang
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
   public class ElementSizeQueue implements SortedEvictionQueue
   {
  -   private Map nodeMap;
  -   private LinkedList evictionList;
  -   private Comparator comparator;
  +   private Map<Fqn, NodeEntry> nodeMap;
  +   private LinkedList<NodeEntry> evictionList;
  +   private Comparator<NodeEntry> comparator;
   
  -   private Set removalQueue;
  +   private Set<NodeEntry> removalQueue;
      private int numElements = 0;
   
      ElementSizeQueue()
      {
  -      nodeMap = new HashMap();
  -      evictionList = new LinkedList();
  +      nodeMap = new HashMap<Fqn, NodeEntry>();
  +      evictionList = new LinkedList<NodeEntry>();
         comparator = new MaxElementComparator();
  -      removalQueue = new HashSet();
  +      removalQueue = new HashSet<NodeEntry>();
      }
   
      public void resortEvictionQueue()
  @@ -50,7 +50,7 @@
         try
         {
            NodeEntry ne;
  -         while ((ne = (NodeEntry) evictionList.getFirst()) != null)
  +         while ((ne = evictionList.getFirst()) != null)
            {
               if (removalQueue.contains(ne))
               {
  @@ -74,7 +74,7 @@
   
      public NodeEntry getNodeEntry(Fqn fqn)
      {
  -      return (NodeEntry) nodeMap.get(fqn);
  +      return nodeMap.get(fqn);
      }
   
      public NodeEntry getNodeEntry(String fqn)
  @@ -90,7 +90,7 @@
   
      public void removeNodeEntry(NodeEntry entry)
      {
  -      NodeEntry ne = (NodeEntry) nodeMap.remove(entry.getFqn());
  +      NodeEntry ne = nodeMap.remove(entry.getFqn());
         if (ne != null)
         {
            // don't remove directly from the LinkedList otherwise we will incur a O(n) = n
  @@ -141,19 +141,19 @@
         this.numElements = 0;
      }
   
  -   final List getEvictionList()
  +   final List<NodeEntry> getEvictionList()
      {
         return evictionList;
      }
   
  -   final Set getRemovalQueue()
  +   final Set<NodeEntry> getRemovalQueue()
      {
         return removalQueue;
      }
   
      final void prune()
      {
  -      Iterator it = evictionList.iterator();
  +      Iterator<NodeEntry> it = evictionList.iterator();
         while (it.hasNext() && removalQueue.size() > 0)
         {
            if (removalQueue.remove(it.next()))
  @@ -163,7 +163,7 @@
         }
      }
   
  -   public Iterator iterate()
  +   public Iterator<NodeEntry> iterate()
      {
         return evictionList.iterator();
      }
  @@ -179,22 +179,20 @@
       * Note: this class has a natural ordering that is inconsistent with equals as defined by the java.lang.Comparator
       * contract.
       */
  -   static class MaxElementComparator implements Comparator
  +   static class MaxElementComparator implements Comparator<NodeEntry>
      {
         MaxElementComparator()
         {
         }
   
  -      public int compare(Object o, Object o1)
  +      public int compare(NodeEntry ne1, NodeEntry ne2)
         {
  -         if (o.equals(o1))
  +         if (ne1.equals(ne2))
            {
               return 0;
            }
  -         NodeEntry ne = (NodeEntry) o;
  -         NodeEntry ne2 = (NodeEntry) o1;
   
  -         int neNumElements = ne.getNumberOfElements();
  +         int neNumElements = ne1.getNumberOfElements();
            int neNumElements2 = ne2.getNumberOfElements();
   
            if (neNumElements > neNumElements2)
  @@ -212,6 +210,7 @@
   
            throw new RuntimeException("Should never reach this condition");
         }
  +
      }
   
   }
  
  
  
  1.6       +5 -8      JBossCache/src/org/jboss/cache/eviction/EvictionQueueList.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: EvictionQueueList.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/eviction/EvictionQueueList.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- EvictionQueueList.java	30 Aug 2006 18:39:42 -0000	1.5
  +++ EvictionQueueList.java	6 Mar 2007 19:18:19 -0000	1.6
  @@ -15,7 +15,7 @@
   
   /**
    * @author Daniel Huang (dhuang at jboss.org)
  - * @version $Revision: 1.5 $
  + * @version $Revision: 1.6 $
    */
   public class EvictionQueueList
   {
  @@ -215,20 +215,17 @@
         return Arrays.asList(toArray()).toString();
      }
   
  -   static class EvictionListComparator implements Comparator
  +   static class EvictionListComparator implements Comparator<EvictionListEntry>
      {
  -      Comparator nodeEntryComparator;
  +      Comparator<NodeEntry> nodeEntryComparator;
   
  -      EvictionListComparator(Comparator nodeEntryComparator)
  +      EvictionListComparator(Comparator<NodeEntry> nodeEntryComparator)
         {
            this.nodeEntryComparator = nodeEntryComparator;
         }
   
  -      public int compare(Object o1, Object o2)
  +      public int compare(EvictionListEntry e1, EvictionListEntry e2)
         {
  -         EvictionListEntry e1 = (EvictionListEntry) o1;
  -         EvictionListEntry e2 = (EvictionListEntry) o2;
  -
            return nodeEntryComparator.compare(e1.node, e2.node);
         }
      }
  
  
  
  1.5       +7 -7      JBossCache/src/org/jboss/cache/eviction/FIFOQueue.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: FIFOQueue.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/eviction/FIFOQueue.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- FIFOQueue.java	8 Jun 2006 17:37:39 -0000	1.4
  +++ FIFOQueue.java	6 Mar 2007 19:18:19 -0000	1.5
  @@ -16,16 +16,16 @@
    * FIFO Eviction Queue implementation for FIFO Policy.
    *
    * @author Daniel Huang (dhuang at jboss.org)
  - * @version $Revision: 1.4 $
  + * @version $Revision: 1.5 $
    */
   public class FIFOQueue implements EvictionQueue
   {
  -   private Map nodeMap;
  +   private Map<Fqn, NodeEntry> nodeMap;
      private int numElements = 0;
   
      FIFOQueue()
      {
  -      nodeMap = new LinkedHashMap();
  +      nodeMap = new LinkedHashMap<Fqn, NodeEntry>();
         // We use a LinkedHashMap here because we want to maintain FIFO ordering and still get the benefits of
         // O(n) = 1 for add/remove/search.
      }
  @@ -42,7 +42,7 @@
         // this code path is *slightly* faster when profiling. 20ms faster iterating over 200000 entries in queue.
         if (nodeMap.size() > 0)
         {
  -         return (NodeEntry) nodeMap.values().iterator().next();
  +         return nodeMap.values().iterator().next();
         }
   
         return null;
  @@ -50,7 +50,7 @@
   
      public NodeEntry getNodeEntry(Fqn fqn)
      {
  -      return (NodeEntry) nodeMap.get(fqn);
  +      return nodeMap.get(fqn);
      }
   
      public NodeEntry getNodeEntry(String fqn)
  @@ -66,7 +66,7 @@
   
      public void removeNodeEntry(NodeEntry entry)
      {
  -      NodeEntry e = (NodeEntry) nodeMap.remove(entry.getFqn());
  +      NodeEntry e = nodeMap.remove(entry.getFqn());
         this.numElements -= e.getNumberOfElements();
      }
   
  @@ -101,7 +101,7 @@
         this.numElements = 0;
      }
   
  -   public Iterator iterate()
  +   public Iterator<NodeEntry> iterate()
      {
         return nodeMap.values().iterator();
      }
  
  
  
  1.6       +19 -21    JBossCache/src/org/jboss/cache/eviction/LFUQueue.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: LFUQueue.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/eviction/LFUQueue.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -b -r1.5 -r1.6
  --- LFUQueue.java	8 Jun 2006 17:37:39 -0000	1.5
  +++ LFUQueue.java	6 Mar 2007 19:18:19 -0000	1.6
  @@ -25,23 +25,23 @@
    * The queue is sorted in least frequently used order.
    *
    * @author Daniel Huang (dhuang at jboss.org)
  - * @version $Revision: 1.5 $
  + * @version $Revision: 1.6 $
    */
   public class LFUQueue implements SortedEvictionQueue
   {
  -   private Map nodeMap;
  -   private LinkedList evictionList;
  -   private Comparator comparator;
  +   private Map<Fqn, NodeEntry> nodeMap;
  +   private LinkedList<NodeEntry> evictionList;
  +   private Comparator<NodeEntry> comparator;
   
  -   private Set removalQueue;
  +   private Set<NodeEntry> removalQueue;
      private int numElements = 0;
   
      LFUQueue()
      {
  -      nodeMap = new HashMap();
  +      nodeMap = new HashMap<Fqn, NodeEntry>();
         comparator = new LFUComparator();
  -      evictionList = new LinkedList();
  -      removalQueue = new HashSet();
  +      evictionList = new LinkedList<NodeEntry>();
  +      removalQueue = new HashSet<NodeEntry>();
      }
   
      /**
  @@ -54,7 +54,7 @@
         try
         {
            NodeEntry ne;
  -         while ((ne = (NodeEntry) evictionList.getFirst()) != null)
  +         while ((ne = evictionList.getFirst()) != null)
            {
               if (removalQueue.contains(ne))
               {
  @@ -78,7 +78,7 @@
   
      public NodeEntry getNodeEntry(Fqn fqn)
      {
  -      return (NodeEntry) nodeMap.get(fqn);
  +      return nodeMap.get(fqn);
      }
   
      public NodeEntry getNodeEntry(String fqn)
  @@ -94,7 +94,7 @@
   
      public void removeNodeEntry(NodeEntry entry)
      {
  -      NodeEntry ne = (NodeEntry) nodeMap.remove(entry.getFqn());
  +      NodeEntry ne = nodeMap.remove(entry.getFqn());
         if (ne != null)
         {
            // don't remove directly from the LinkedList otherwise we will incur a O(n) = n
  @@ -152,7 +152,7 @@
   
      void prune()
      {
  -      Iterator it = this.iterate();
  +      Iterator<NodeEntry> it = this.iterate();
         while (it.hasNext() && removalQueue.size() > 0)
         {
            if (removalQueue.remove(it.next()))
  @@ -163,18 +163,18 @@
      }
   
      // provided as friend access for unit testing only.
  -   final List getEvictionList()
  +   final List<NodeEntry> getEvictionList()
      {
         return this.evictionList;
      }
   
      // provided as friend access for unit testing only.
  -   final Set getRemovalQueue()
  +   final Set<NodeEntry> getRemovalQueue()
      {
         return this.removalQueue;
      }
   
  -   public Iterator iterate()
  +   public Iterator<NodeEntry> iterate()
      {
         return evictionList.iterator();
      }
  @@ -190,22 +190,20 @@
       * Note: this class has a natural ordering that is inconsistent with equals as defined by the java.lang.Comparator
       * contract.
       */
  -   static class LFUComparator implements Comparator
  +   static class LFUComparator implements Comparator<NodeEntry>
      {
         LFUComparator()
         {
         }
   
  -      public int compare(Object o, Object o1)
  +      public int compare(NodeEntry ne1, NodeEntry ne2)
         {
  -         if (o.equals(o1))
  +         if (ne1.equals(ne2))
            {
               return 0;
            }
  -         NodeEntry ne = (NodeEntry) o;
  -         NodeEntry ne2 = (NodeEntry) o1;
   
  -         int neNodeHits = ne.getNumberOfNodeVisits();
  +         int neNodeHits = ne1.getNumberOfNodeVisits();
            int ne2NodeHits = ne2.getNumberOfNodeVisits();
   
            if (neNodeHits > ne2NodeHits)
  
  
  
  1.5       +13 -13    JBossCache/src/org/jboss/cache/eviction/LRUQueue.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: LRUQueue.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/eviction/LRUQueue.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- LRUQueue.java	8 Jun 2006 17:37:39 -0000	1.4
  +++ LRUQueue.java	6 Mar 2007 19:18:19 -0000	1.5
  @@ -19,19 +19,19 @@
    * One sorted by maxAge and the other sorted by idleTime.
    *
    * @author Daniel Huang (dhuang at jboss.org)
  - * @version $Revision: 1.4 $
  + * @version $Revision: 1.5 $
    */
   public class LRUQueue implements EvictionQueue
   {
  -   private Map maxAgeQueue;
  -   private Map lruQueue;
  +   private Map<Fqn, NodeEntry> maxAgeQueue;
  +   private Map<Fqn, NodeEntry> lruQueue;
      private long alternatingCount = 0;
      private int numElements = 0;
   
      LRUQueue()
      {
  -      maxAgeQueue = new LinkedHashMap();
  -      lruQueue = new LinkedHashMap(16, 0.75f, true);
  +      maxAgeQueue = new LinkedHashMap<Fqn, NodeEntry>();
  +      lruQueue = new LinkedHashMap<Fqn, NodeEntry>(16, 0.75f, true);
      }
   
      void reorderByLRU(Fqn fqn)
  @@ -74,7 +74,7 @@
      {
         if (lruQueue.size() > 0)
         {
  -         return (NodeEntry) lruQueue.values().iterator().next();
  +         return lruQueue.values().iterator().next();
         }
   
         return null;
  @@ -84,7 +84,7 @@
      {
         if (maxAgeQueue.size() > 0)
         {
  -         return (NodeEntry) maxAgeQueue.values().iterator().next();
  +         return maxAgeQueue.values().iterator().next();
         }
   
         return null;
  @@ -92,7 +92,7 @@
   
      public NodeEntry getNodeEntry(Fqn fqn)
      {
  -      return (NodeEntry) lruQueue.get(fqn);
  +      return lruQueue.get(fqn);
      }
   
      public NodeEntry getNodeEntry(String fqn)
  @@ -124,8 +124,8 @@
            return;
         }
         Fqn fqn = entry.getFqn();
  -      NodeEntry ne1 = (NodeEntry) lruQueue.remove(fqn);
  -      NodeEntry ne2 = (NodeEntry) maxAgeQueue.remove(fqn);
  +      NodeEntry ne1 = lruQueue.remove(fqn);
  +      NodeEntry ne2 = maxAgeQueue.remove(fqn);
   
         if (ne1 == null || ne2 == null)
         {
  @@ -170,17 +170,17 @@
         this.numElements += difference;
      }
   
  -   public Iterator iterate()
  +   public Iterator<NodeEntry> iterate()
      {
         return lruQueue.values().iterator();
      }
   
  -   final Iterator iterateMaxAgeQueue()
  +   final Iterator<NodeEntry> iterateMaxAgeQueue()
      {
         return maxAgeQueue.values().iterator();
      }
   
  -   final Iterator iterateLRUQueue()
  +   final Iterator<NodeEntry> iterateLRUQueue()
      {
         return lruQueue.values().iterator();
      }
  
  
  
  1.8       +6 -6      JBossCache/src/org/jboss/cache/eviction/MRUQueue.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: MRUQueue.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/eviction/MRUQueue.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- MRUQueue.java	15 Nov 2006 17:01:30 -0000	1.7
  +++ MRUQueue.java	6 Mar 2007 19:18:19 -0000	1.8
  @@ -22,20 +22,20 @@
    * a node that is used to the top of the eviction stack.
    *
    * @author Daniel Huang (dhuang at jboss.org)
  - * @version $Revision: 1.7 $
  + * @version $Revision: 1.8 $
    */
   public class MRUQueue implements EvictionQueue
   {
      // we use our own Stack/Linked List implementation here because it guarantees O(n) = 1 for add, remove, get and
      // we can sort it in order of MRU implicitly while still getting O(n) = 1 access time
      // throughout.
  -   Map nodeMap;
  +   Map<Fqn, EvictionListEntry> nodeMap;
      EvictionQueueList list;
      private int numElements = 0;
   
      MRUQueue()
      {
  -      nodeMap = new HashMap();
  +      nodeMap = new HashMap<Fqn, EvictionListEntry>();
         list = new EvictionQueueList();
      }
   
  @@ -48,7 +48,7 @@
       */
      void moveToTopOfStack(Fqn fqn)
      {
  -      EvictionListEntry le = (EvictionListEntry) nodeMap.remove(fqn);
  +      EvictionListEntry le = nodeMap.remove(fqn);
         if (le != null)
         {
            list.remove(le);
  @@ -80,7 +80,7 @@
   
      public NodeEntry getNodeEntry(Fqn fqn)
      {
  -      EvictionListEntry le = (EvictionListEntry) nodeMap.get(fqn);
  +      EvictionListEntry le = nodeMap.get(fqn);
         if (le != null)
            return le.node;
   
  @@ -99,7 +99,7 @@
   
      public void removeNodeEntry(NodeEntry entry)
      {
  -      EvictionListEntry le = (EvictionListEntry) nodeMap.remove(entry.getFqn());
  +      EvictionListEntry le = nodeMap.remove(entry.getFqn());
         if (le != null)
         {
            list.remove(le);
  
  
  



More information about the jboss-cvs-commits mailing list