[infinispan-commits] Infinispan SVN: r1402 - trunk/core/src/main/java/org/infinispan/interceptors.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Wed Jan 20 10:26:56 EST 2010


Author: manik.surtani at jboss.com
Date: 2010-01-20 10:26:56 -0500 (Wed, 20 Jan 2010)
New Revision: 1402

Modified:
   trunk/core/src/main/java/org/infinispan/interceptors/CacheLoaderInterceptor.java
Log:
Better impl

Modified: trunk/core/src/main/java/org/infinispan/interceptors/CacheLoaderInterceptor.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/interceptors/CacheLoaderInterceptor.java	2010-01-20 15:22:57 UTC (rev 1401)
+++ trunk/core/src/main/java/org/infinispan/interceptors/CacheLoaderInterceptor.java	2010-01-20 15:26:56 UTC (rev 1402)
@@ -27,11 +27,11 @@
 import org.infinispan.commands.write.RemoveCommand;
 import org.infinispan.commands.write.ReplaceCommand;
 import org.infinispan.container.DataContainer;
+import org.infinispan.container.EntryFactory;
 import org.infinispan.container.entries.CacheEntry;
 import org.infinispan.container.entries.InternalCacheEntry;
 import org.infinispan.container.entries.MVCCEntry;
 import org.infinispan.context.InvocationContext;
-import org.infinispan.container.EntryFactory;
 import org.infinispan.factories.annotations.Inject;
 import org.infinispan.factories.annotations.Start;
 import org.infinispan.interceptors.base.JmxStatsCommandInterceptor;
@@ -115,6 +115,20 @@
       CacheEntry e = entryFactory.wrapEntryForReading(ctx, key);
       if (e == null || e.isNull()) {
 
+         // Obtain a temporary lock to verify the key is not being concurrently added
+         boolean keyLocked = entryFactory.acquireLock(ctx, key);
+         boolean unlockOnWayOut = false;
+         try {
+            // check again, in case there is a concurrent addition
+            if (dataContainer.containsKey(key)) {
+               log.trace("No need to load.  Key exists in the data container.");
+               unlockOnWayOut = true;
+               return true;
+            }
+         } finally {
+            if (keyLocked && unlockOnWayOut) entryFactory.releaseLock(key);
+         }
+
          // we *may* need to load this.
          InternalCacheEntry loaded = loader.load(key);
          if (loaded == null) {
@@ -122,16 +136,6 @@
             return false;
          }
 
-         // Obtain a temporary lock to verify the key is not being concurrently added
-         boolean keyLocked = entryFactory.acquireLock(ctx, key);
-
-         // check again, in case there is a concurrent addition
-         if (dataContainer.containsKey(key)) {
-            if (keyLocked) entryFactory.releaseLock(key);
-            log.trace("No need to load.  Key exists in the data container.");
-            return true;
-         }
-
          // Reuse the lock and create a new entry for loading
          MVCCEntry n = entryFactory.wrapEntryForWriting(ctx, key, true, false, keyLocked, false);
          putLoadedEntryInContainer(ctx, key, n, loaded);



More information about the infinispan-commits mailing list