[jbosscache-commits] JBoss Cache SVN: r6551 - pojo/trunk/src/main/java/org/jboss/cache/pojo/impl.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Fri Aug 8 23:21:50 EDT 2008


Author: jason.greene at jboss.com
Date: 2008-08-08 23:21:50 -0400 (Fri, 08 Aug 2008)
New Revision: 6551

Modified:
   pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/NotificationDispatcher.java
   pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/ObjectGraphHandler.java
   pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java
   pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoInstance.java
Log:
Fix synchronization issues in reference changes


Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/NotificationDispatcher.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/NotificationDispatcher.java	2008-08-08 19:29:53 UTC (rev 6550)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/NotificationDispatcher.java	2008-08-09 03:21:50 UTC (rev 6551)
@@ -121,7 +121,7 @@
          return ((Entry)o).listener == this.listener;
       }
 
-      private static Map<Class<?>, List<Method>> buildNotifiers(Class clazz)
+      private static Map<Class<?>, List<Method>> buildNotifiers(Class<?> clazz)
       {
          if (! Modifier.isPublic(clazz.getModifiers()))
             throw new IllegalArgumentException("Listener must be public! Class:" + clazz.getName());

Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/ObjectGraphHandler.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/ObjectGraphHandler.java	2008-08-08 19:29:53 UTC (rev 6550)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/ObjectGraphHandler.java	2008-08-09 03:21:50 UTC (rev 6551)
@@ -99,15 +99,11 @@
     */
    private void removeFromReference(Fqn<?> originalFqn, Reference reference) throws CacheException
    {
-      synchronized (originalFqn)
-      {  // we lock the internal fqn here so no one else has access.
-         // Decrement ref counting on the internal node
-         if (decrementRefCount(originalFqn, reference) == PojoInstance.INITIAL_COUNTER_VALUE)
-         {
-            // No one is referring it so it is safe to remove
-            // TODO we should make sure the parent nodes are also removed they are empty as well.
-            cache.detach(originalFqn);
-         }
+      if (decrementRefCount(originalFqn, reference) == PojoInstance.INITIAL_COUNTER_VALUE)
+      {
+         // No one is referring it so it is safe to remove
+         // TODO we should make sure the parent nodes are also removed they are empty as well.
+         cache.detach(originalFqn);
       }
    }
 
@@ -120,11 +116,8 @@
     */
    private void setupRefCounting(Fqn<?> fqn, Reference reference) throws CacheException
    {
-      synchronized (fqn)
-      {
-         // increment the reference counting
-         incrementRefCount(fqn, reference);
-      }
+      // increment the reference counting
+      incrementRefCount(fqn, reference);
    }
 
    private int incrementRefCount(Fqn<?> originalFqn, Reference reference) throws CacheException

Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java	2008-08-08 19:29:53 UTC (rev 6550)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoCacheDelegate.java	2008-08-09 03:21:50 UTC (rev 6551)
@@ -125,6 +125,8 @@
       Reference reference = new ReferenceImpl(fqn, field);
       if (internalFqn != null)
       {
+         // Lock the internal fqn, before the ref count is checked
+         internal_.lockPojo(internalFqn);
          graphHandler_.put(internalFqn, reference , obj);
       }
       else
@@ -232,6 +234,8 @@
 
       Fqn<?> internalFqn = pojoReference.getFqn();
 
+
+
       if (log.isDebugEnabled())
       {
          log.debug("removeObject(): removing object from id: " + fqn
@@ -242,6 +246,9 @@
       if (result == null)
          return null;
 
+      // Lock the internal fqn, before the ref count is checked
+      internal_.lockPojo(internalFqn);
+
       Reference reference = new ReferenceImpl(fqn, field);
       if (graphHandler_.isMultipleReferenced(internalFqn))
       {

Modified: pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoInstance.java
===================================================================
--- pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoInstance.java	2008-08-08 19:29:53 UTC (rev 6550)
+++ pojo/trunk/src/main/java/org/jboss/cache/pojo/impl/PojoInstance.java	2008-08-09 03:21:50 UTC (rev 6551)
@@ -6,12 +6,14 @@
  */
 package org.jboss.cache.pojo.impl;
 
-import org.jboss.cache.Fqn;
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
 import org.jboss.cache.pojo.Reference;
 
-import java.io.Serializable;
-import java.util.*;
-
 /**
  * POJO class metadata information.
  * When an object is looked up or put in PojoCache, this object will be advised with a CacheFieldInterceptor.
@@ -39,7 +41,7 @@
    private int refCount_ = INITIAL_COUNTER_VALUE;
 
    // List of fqns that reference this fqn.
-   private Set<Reference> referencedBy_ = new HashSet<Reference>(4);
+   private final Set<Reference> referencedBy_ = new HashSet<Reference>(4);
    private Class<?> clazz_ = null;
    private transient PojoUtil util_ = new PojoUtil();
 
@@ -105,9 +107,9 @@
       return refCount_;
    }
 
-   public Collection<Reference> getReferences()
+   public synchronized Collection<Reference> getReferences()
    {
-      return Collections.unmodifiableCollection(referencedBy_);
+      return Collections.unmodifiableCollection(new HashSet<Reference>(referencedBy_));
    }
 
    public String toString()




More information about the jbosscache-commits mailing list