[jboss-cvs] JBossCache/src/org/jboss/cache/eviction ...
Elias Ross
genman at noderunner.net
Wed May 9 04:06:31 EDT 2007
User: genman
Date: 07/05/09 04:06:31
Modified: src/org/jboss/cache/eviction ExpirationAlgorithm.java
Log:
JBCACHE-1051
Revision Changes Path
1.10 +15 -18 JBossCache/src/org/jboss/cache/eviction/ExpirationAlgorithm.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ExpirationAlgorithm.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/eviction/ExpirationAlgorithm.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- ExpirationAlgorithm.java 7 Feb 2007 22:06:56 -0000 1.9
+++ ExpirationAlgorithm.java 9 May 2007 08:06:31 -0000 1.10
@@ -92,21 +92,19 @@
private void setExpiration(Fqn fqn, Long l)
{
- boolean found = set.remove(new ExpirationEntry(fqn));
- if (found && log.isTraceEnabled())
- log.trace("removed old expiration for " + fqn);
ExpirationEntry ee = new ExpirationEntry(fqn, l);
if (log.isTraceEnabled())
log.trace("adding eviction entry: " + ee);
set.add(ee);
}
+ @SuppressWarnings("unchecked")
private Long getExpiration(Fqn fqn)
{
- NodeSPI n = policy.getCache().peek(fqn, false);
+ NodeSPI<String, Long> n = policy.getCache().peek(fqn, false);
if (n == null)
return null;
- return (Long)n.getDirect(config.getExpirationKeyName());
+ return n.getDirect(config.getExpirationKeyName());
}
@Override
@@ -126,7 +124,8 @@
case REMOVE_ELEMENT_EVENT:
case REMOVE_NODE_EVENT:
case UNMARK_USE_EVENT:
- removeEvictionEntry(node);
+ // Removals will be noticed when double-checking expiry time
+ // removeEvictionEntry(node);
break;
case VISIT_NODE_EVENT:
// unused
@@ -161,6 +160,13 @@
for (Iterator<ExpirationEntry> i = set.iterator(); i.hasNext();)
{
ExpirationEntry ee = i.next();
+ Long ce = getExpiration(ee.getFqn());
+ if (ce == null || ce > ee.getExpiration())
+ {
+ // Expiration now older
+ i.remove();
+ continue;
+ }
if (ee.getExpiration() < now || (max != 0 && set.size() > max))
{
i.remove();
@@ -177,13 +183,6 @@
"Set expiration for nodes in this region");
}
- private void removeEvictionEntry(EvictedEventNode node)
- {
- Fqn fqn = node.getFqn();
- if (getExpiration(fqn) == null)
- set.remove(new ExpirationEntry(fqn));
- }
-
@Override
public void resetEvictionQueue(Region region)
{
@@ -230,12 +229,10 @@
}
/**
- * Returns true if the FQN are the same, else compares expiration, then FQN order.
+ * Compares expiration, then FQN order.
*/
public int compareTo(ExpirationEntry ee)
{
- if (fqn.equals(ee.fqn))
- return 0;
long n = expiration - ee.expiration;
if (n < 0)
return -1;
@@ -265,12 +262,12 @@
if (!(o instanceof ExpirationEntry))
return false;
ExpirationEntry ee = (ExpirationEntry) o;
- return fqn.equals(ee.fqn);
+ return expiration == ee.expiration && fqn.equals(ee.fqn);
}
public int hashCode()
{
- return fqn.hashCode();
+ return (int)expiration ^ fqn.hashCode();
}
public String toString()
More information about the jboss-cvs-commits
mailing list