[hibernate-commits] Hibernate SVN: r14106 - core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/timestamp.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Oct 18 23:13:41 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-10-18 23:13:41 -0400 (Thu, 18 Oct 2007)
New Revision: 14106

Modified:
   core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/timestamp/TimestampsRegionImpl.java
Log:
Evict fixes

Modified: core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/timestamp/TimestampsRegionImpl.java
===================================================================
--- core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/timestamp/TimestampsRegionImpl.java	2007-10-19 03:13:13 UTC (rev 14105)
+++ core/trunk/cache-jbosscache2/src/main/java/org/hibernate/cache/jbc2/timestamp/TimestampsRegionImpl.java	2007-10-19 03:13:41 UTC (rev 14106)
@@ -32,7 +32,9 @@
 import org.jboss.cache.config.Option;
 import org.jboss.cache.notifications.annotation.CacheListener;
 import org.jboss.cache.notifications.annotation.NodeModified;
+import org.jboss.cache.notifications.annotation.NodeRemoved;
 import org.jboss.cache.notifications.event.NodeModifiedEvent;
+import org.jboss.cache.notifications.event.NodeRemovedEvent;
 
 /**
  * Defines the behavior of the timestamps cache region for JBossCache 2.x.
@@ -81,7 +83,7 @@
         // TODO Is this a valid operation on a timestamps cache?
         localCache.remove(key);
         Option opt = getNonLockingDataVersionOption(true);
-        CacheHelper.remove(getCacheInstance(), getRegionFqn(), key, opt);
+        CacheHelper.removeNode(getCacheInstance(), getRegionFqn(), key, opt);
     }
 
     public void evictAll() throws CacheException {
@@ -89,6 +91,8 @@
         localCache.clear();
         Option opt = getNonLockingDataVersionOption(true);
         CacheHelper.removeAll(getCacheInstance(), getRegionFqn(), opt);
+        // Restore the region root node
+        CacheHelper.addNode(getCacheInstance(), getRegionFqn(), false, true, null);   
     }
 
     public Object get(Object key) throws CacheException {
@@ -121,11 +125,11 @@
             // prevents reads and other updates
             Transaction tx = suspend();
             try {
+                // TODO Why not use the timestamp in a DataVersion?
+                Option opt = getNonLockingDataVersionOption(false);
                 // We ensure ASYNC semantics (JBCACHE-1175)
-                Option opt = getNonLockingDataVersionOption(false);
                 opt.setForceAsynchronous(true);
-                getCacheInstance().getInvocationContext().setOptionOverrides(opt);
-                getCacheInstance().put(new Fqn(regionFqn, key), ITEM, value);
+                CacheHelper.put(getCacheInstance(), getRegionFqn(), key, value, opt);
             } catch (Exception e) {
                 throw new CacheException(e);
             } finally {
@@ -160,6 +164,30 @@
         }
     }
 
+    /**
+     * Monitors cache events and updates the local cache
+     * 
+     * @param event
+     */
+    @NodeRemoved
+    public void nodeRemoved(NodeRemovedEvent event) {
+        if (event.isOriginLocal() || event.isPre())
+            return;
+
+        Fqn fqn = event.getFqn();
+        Fqn regFqn = getRegionFqn();
+        if (fqn.size() == regFqn.size() + 1 && fqn.isChildOf(regFqn)) {
+            Object key = fqn.get(regFqn.size());
+            localCache.remove(key);
+        }
+        else if (fqn.equals(regFqn)) {
+            localCache.clear();
+        }
+    }
+
+    /**
+     * Brings all data from the distributed cache into our local cache.
+     */
     private void populateLocalCache() {
         Set children = CacheHelper.getChildrenNames(getCacheInstance(), getRegionFqn());
         for (Object key : children) {
@@ -189,9 +217,10 @@
             if (increase) {
                 oldVal = (Long) localCache.put(key, value);
                 // Double check that it was an increase
-                if (oldVal != null && oldVal.longValue() > newVal) {
+                if (oldVal != null && oldVal.longValue() > newVal) {                    
                     // Nope; Restore the old value
-                    increase = updateLocalCache(key, oldVal);
+                    updateLocalCache(key, oldVal);
+                    increase = false;
                 }
             }
         } catch (ClassCastException cce) {




More information about the hibernate-commits mailing list