[infinispan-commits] Infinispan SVN: r2001 - in branches/4.1.x/core/src: main/java/org/infinispan/container/entries and 2 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Wed Jul 7 10:34:44 EDT 2010


Author: manik.surtani at jboss.com
Date: 2010-07-07 10:34:43 -0400 (Wed, 07 Jul 2010)
New Revision: 2001

Modified:
   branches/4.1.x/core/src/main/java/org/infinispan/container/DefaultDataContainer.java
   branches/4.1.x/core/src/main/java/org/infinispan/container/entries/ImmortalCacheEntry.java
   branches/4.1.x/core/src/main/java/org/infinispan/container/entries/InternalCacheEntry.java
   branches/4.1.x/core/src/main/java/org/infinispan/container/entries/InternalEntryFactory.java
   branches/4.1.x/core/src/main/java/org/infinispan/container/entries/MortalCacheEntry.java
   branches/4.1.x/core/src/main/java/org/infinispan/container/entries/TransientCacheEntry.java
   branches/4.1.x/core/src/main/java/org/infinispan/container/entries/TransientMortalCacheEntry.java
   branches/4.1.x/core/src/main/java/org/infinispan/util/Immutables.java
   branches/4.1.x/core/src/test/java/org/infinispan/container/SimpleDataContainerTest.java
Log:
[ISPN-528] (replace(K key, V value, long lifespan, TimeUnit unit) does not extend lifespan)

Modified: branches/4.1.x/core/src/main/java/org/infinispan/container/DefaultDataContainer.java
===================================================================
--- branches/4.1.x/core/src/main/java/org/infinispan/container/DefaultDataContainer.java	2010-07-07 13:21:12 UTC (rev 2000)
+++ branches/4.1.x/core/src/main/java/org/infinispan/container/DefaultDataContainer.java	2010-07-07 14:34:43 UTC (rev 2001)
@@ -166,6 +166,9 @@
             } else if (e != original) {
                // the entry has changed type, but still can expire!
                mortalEntries.put(k, e);
+            } else {
+               // we have the same instance.  So we need to reincarnate.
+               e.reincarnate();
             }
             successfulPut(e, false);
          } else {

Modified: branches/4.1.x/core/src/main/java/org/infinispan/container/entries/ImmortalCacheEntry.java
===================================================================
--- branches/4.1.x/core/src/main/java/org/infinispan/container/entries/ImmortalCacheEntry.java	2010-07-07 13:21:12 UTC (rev 2000)
+++ branches/4.1.x/core/src/main/java/org/infinispan/container/entries/ImmortalCacheEntry.java	2010-07-07 14:34:43 UTC (rev 2001)
@@ -54,6 +54,10 @@
       // no-op
    }
 
+   public final void reincarnate() {
+      // no-op
+   }
+
    public InternalCacheValue toInternalCacheValue() {
       return cacheValue;
    }

Modified: branches/4.1.x/core/src/main/java/org/infinispan/container/entries/InternalCacheEntry.java
===================================================================
--- branches/4.1.x/core/src/main/java/org/infinispan/container/entries/InternalCacheEntry.java	2010-07-07 13:21:12 UTC (rev 2000)
+++ branches/4.1.x/core/src/main/java/org/infinispan/container/entries/InternalCacheEntry.java	2010-07-07 14:34:43 UTC (rev 2001)
@@ -54,6 +54,11 @@
    void touch();
 
    /**
+    * "Reincarnates" an entry.  Essentially, resets the 'created' timestamp of the entry to the current time.
+    */
+   void reincarnate();
+
+   /**
     * Creates a representation of this entry as an {@link org.infinispan.container.entries.InternalCacheValue}. The main
     * purpose of this is to provide a representation that does <i>not</i> have a reference to the key. This is useful in
     * situations where the key is already known or stored elsewhere, making serialization and deserialization more

Modified: branches/4.1.x/core/src/main/java/org/infinispan/container/entries/InternalEntryFactory.java
===================================================================
--- branches/4.1.x/core/src/main/java/org/infinispan/container/entries/InternalEntryFactory.java	2010-07-07 13:21:12 UTC (rev 2000)
+++ branches/4.1.x/core/src/main/java/org/infinispan/container/entries/InternalEntryFactory.java	2010-07-07 14:34:43 UTC (rev 2001)
@@ -78,7 +78,8 @@
             if (maxIdle < 0) {
                return new MortalCacheEntry(ice.getKey(), ice.getValue(), lifespan);
             } else {
-               return new TransientMortalCacheEntry(ice.getKey(), ice.getValue(), maxIdle, lifespan, System.currentTimeMillis(), ice.getCreated());
+               long ctm = System.currentTimeMillis();
+               return new TransientMortalCacheEntry(ice.getKey(), ice.getValue(), maxIdle, lifespan, ctm, ctm);
             }
          }
       } else if (ice instanceof MortalCacheEntry) {
@@ -93,7 +94,8 @@
                ice.setLifespan(lifespan);
                return ice;
             } else {
-               return new TransientMortalCacheEntry(ice.getKey(), ice.getValue(), maxIdle, lifespan, System.currentTimeMillis(), ice.getCreated());
+               long ctm = System.currentTimeMillis();
+               return new TransientMortalCacheEntry(ice.getKey(), ice.getValue(), maxIdle, lifespan, ctm, ctm);
             }
          }
       } else if (ice instanceof TransientCacheEntry) {
@@ -108,7 +110,8 @@
             if (maxIdle < 0) {
                return new MortalCacheEntry(ice.getKey(), ice.getValue(), lifespan);
             } else {
-               return new TransientMortalCacheEntry(ice.getKey(), ice.getValue(), maxIdle, lifespan, System.currentTimeMillis(), ice.getCreated());
+               long ctm = System.currentTimeMillis();
+               return new TransientMortalCacheEntry(ice.getKey(), ice.getValue(), maxIdle, lifespan, ctm, ctm);
             }
          }
       } else if (ice instanceof TransientMortalCacheEntry) {

Modified: branches/4.1.x/core/src/main/java/org/infinispan/container/entries/MortalCacheEntry.java
===================================================================
--- branches/4.1.x/core/src/main/java/org/infinispan/container/entries/MortalCacheEntry.java	2010-07-07 13:21:12 UTC (rev 2000)
+++ branches/4.1.x/core/src/main/java/org/infinispan/container/entries/MortalCacheEntry.java	2010-07-07 14:34:43 UTC (rev 2001)
@@ -71,6 +71,10 @@
       // no-op
    }
 
+   public final void reincarnate() {
+      cacheValue.created = System.currentTimeMillis();
+   }
+
    public InternalCacheValue toInternalCacheValue() {
       return cacheValue;
    }

Modified: branches/4.1.x/core/src/main/java/org/infinispan/container/entries/TransientCacheEntry.java
===================================================================
--- branches/4.1.x/core/src/main/java/org/infinispan/container/entries/TransientCacheEntry.java	2010-07-07 13:21:12 UTC (rev 2000)
+++ branches/4.1.x/core/src/main/java/org/infinispan/container/entries/TransientCacheEntry.java	2010-07-07 14:34:43 UTC (rev 2001)
@@ -41,6 +41,10 @@
       cacheValue.lastUsed = System.currentTimeMillis();
    }
 
+   public final void reincarnate() {
+      // no-op
+   }   
+
    public final boolean canExpire() {
       return true;
    }

Modified: branches/4.1.x/core/src/main/java/org/infinispan/container/entries/TransientMortalCacheEntry.java
===================================================================
--- branches/4.1.x/core/src/main/java/org/infinispan/container/entries/TransientMortalCacheEntry.java	2010-07-07 13:21:12 UTC (rev 2000)
+++ branches/4.1.x/core/src/main/java/org/infinispan/container/entries/TransientMortalCacheEntry.java	2010-07-07 14:34:43 UTC (rev 2001)
@@ -86,6 +86,10 @@
       cacheValue.lastUsed = System.currentTimeMillis();
    }
 
+   public final void reincarnate() {
+      cacheValue.created = System.currentTimeMillis();
+   }   
+
    public long getMaxIdle() {
       return cacheValue.maxIdle;
    }

Modified: branches/4.1.x/core/src/main/java/org/infinispan/util/Immutables.java
===================================================================
--- branches/4.1.x/core/src/main/java/org/infinispan/util/Immutables.java	2010-07-07 13:21:12 UTC (rev 2000)
+++ branches/4.1.x/core/src/main/java/org/infinispan/util/Immutables.java	2010-07-07 14:34:43 UTC (rev 2001)
@@ -504,6 +504,10 @@
          throw new UnsupportedOperationException();
       }
 
+      public void reincarnate() {
+         throw new UnsupportedOperationException();
+      }
+
       public void commit(DataContainer container) {
          throw new UnsupportedOperationException();
       }

Modified: branches/4.1.x/core/src/test/java/org/infinispan/container/SimpleDataContainerTest.java
===================================================================
--- branches/4.1.x/core/src/test/java/org/infinispan/container/SimpleDataContainerTest.java	2010-07-07 13:21:12 UTC (rev 2000)
+++ branches/4.1.x/core/src/test/java/org/infinispan/container/SimpleDataContainerTest.java	2010-07-07 14:34:43 UTC (rev 2001)
@@ -57,7 +57,7 @@
       assert entry.getCreated() <= System.currentTimeMillis();
 
       dc.put("k", "v", 0, -1);
-
+      Thread.sleep(10);
       assert dc.get("k") == null;
       assert dc.size() == 0;
 



More information about the infinispan-commits mailing list