User: simone
Date: 00/12/18 02:27:57
Modified: src/main/org/jboss/util LRUCachePolicy.java
Log:
Updated to allow subclasses override callbacks to perform specific actions.
Revision Changes Path
1.7 +23 -3 jboss/src/main/org/jboss/util/LRUCachePolicy.java
Index: LRUCachePolicy.java
===================================================================
RCS file: /products/cvs/ejboss/jboss/src/main/org/jboss/util/LRUCachePolicy.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- LRUCachePolicy.java 2000/12/12 09:53:34 1.6
+++ LRUCachePolicy.java 2000/12/18 10:27:57 1.7
@@ -12,7 +12,7 @@
* Implementation of a Least Recently Used cache policy.
*
* @author Simone Bordet ([EMAIL PROTECTED])
- * @version $Revision: 1.6 $
+ * @version $Revision: 1.7 $
*/
public class LRUCachePolicy
implements CachePolicy
@@ -216,7 +216,7 @@
/**
* Double queued list used to store cache entries.
*/
- protected class LRUList
+ public class LRUList
{
/** The maximum capacity of the cache list */
public int m_maxCapacity;
@@ -265,6 +265,7 @@
m_head = entry;
m_tail = entry;
++m_count;
+ entryAdded(entry);
}
else if (m_count == 1 && m_head == entry) {}
// there is only the head and I want to promote it, do nothing
else if (m_count < m_capacity)
@@ -274,6 +275,7 @@
m_head.m_prev = entry;
m_head = entry;
++m_count;
+ entryAdded(entry);
}
else if (m_count < m_maxCapacity)
{
@@ -282,7 +284,10 @@
m_head.m_prev = entry;
m_head = entry;
++m_count;
+ int oldCapacity = m_capacity;
++m_capacity;
+ entryAdded(entry);
+ capacityChanged(oldCapacity);
}
else {throw new IllegalStateException("Attempt
to put a new cache entry on a full cache");}
}
@@ -366,7 +371,22 @@
}
}
--m_count;
+ entryRemoved(entry);
}
+ /**
+ * Callback that signals that the given entry has been added to the
cache.
+ */
+ protected void entryAdded(LRUCacheEntry entry) {}
+ /**
+ * Callback that signals that the given entry has been removed from
the cache.
+ */
+ protected void entryRemoved(LRUCacheEntry entry) {}
+ /**
+ * Callback that signals that the capacity of the cache is changed.
+ * @param oldCapacity the capacity before the change happened
+ */
+ protected void capacityChanged(int oldCapacity) {}
+
public String toString()
{
String s = Integer.toHexString(super.hashCode());
@@ -382,7 +402,7 @@
/**
* Double linked cell used as entry in the cache list.
*/
- protected class LRUCacheEntry
+ public class LRUCacheEntry
{
/** Reference to the next cell in the list */
public LRUCacheEntry m_next;