[jboss-cvs] JBossCache/src/org/jboss/cache/loader ...

Manik Surtani manik at jboss.org
Tue Jun 19 10:27:48 EDT 2007


  User: msurtani
  Date: 07/06/19 10:27:48

  Modified:    src/org/jboss/cache/loader  ClusteredCacheLoader.java
  Log:
  CCL thread safety
  
  Revision  Changes    Path
  1.24      +74 -24    JBossCache/src/org/jboss/cache/loader/ClusteredCacheLoader.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ClusteredCacheLoader.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/ClusteredCacheLoader.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -b -r1.23 -r1.24
  --- ClusteredCacheLoader.java	8 Jun 2007 16:08:21 -0000	1.23
  +++ ClusteredCacheLoader.java	19 Jun 2007 14:27:48 -0000	1.24
  @@ -6,6 +6,7 @@
    */
   package org.jboss.cache.loader;
   
  +import net.jcip.annotations.ThreadSafe;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.jboss.cache.Fqn;
  @@ -13,6 +14,7 @@
   import org.jboss.cache.NodeSPI;
   import org.jboss.cache.RegionManager;
   import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
  +import org.jboss.cache.lock.StripedLock;
   import org.jboss.cache.marshall.MethodCall;
   import org.jboss.cache.marshall.MethodCallFactory;
   import org.jboss.cache.marshall.MethodDeclarations;
  @@ -21,6 +23,7 @@
   
   import java.io.ObjectInputStream;
   import java.io.ObjectOutputStream;
  +import java.util.Collections;
   import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
  @@ -35,10 +38,11 @@
    *
    * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
    */
  + at ThreadSafe
   public class ClusteredCacheLoader extends AbstractCacheLoader
   {
      private static Log log = LogFactory.getLog(ClusteredCacheLoader.class);
  -
  +   private StripedLock lock = new StripedLock();
      private ClusteredCacheLoaderConfig config;
   
      /**
  @@ -64,10 +68,19 @@
   
      public Set<String> getChildrenNames(Fqn fqn) throws Exception
      {
  +      if (!cache.getInvocationContext().isOriginLocal()) return Collections.emptySet();
  +      lock.acquireLock(fqn, true);
  +      try
  +      {
         MethodCall call = MethodCallFactory.create(MethodDeclarations.getChildrenNamesMethodLocal, fqn);
         Object resp = callRemote(call);
         return (Set<String>) resp;
      }
  +      finally
  +      {
  +         lock.releaseLock(fqn);
  +      }
  +   }
   
      private Object callRemote(MethodCall call) throws Exception
      {
  @@ -124,23 +137,47 @@
   
      protected Map get0(Fqn name) throws Exception
      {
  +      // DON'T make a remote call if this is a remote call in the first place - leads to deadlocks - JBCACHE-1103
  +      if (!cache.getInvocationContext().isOriginLocal()) return Collections.emptyMap();
  +      lock.acquireLock(name, true);
  +      try
  +      {
         MethodCall call = MethodCallFactory.create(MethodDeclarations.getDataMapMethodLocal, name);
         Object resp = callRemote(call);
         return (Map) resp;
      }
  +      finally
  +      {
  +         lock.releaseLock(name);
  +      }
  +   }
   
      public boolean exists(Fqn name) throws Exception
      {
  +      // DON'T make a remote call if this is a remote call in the first place - leads to deadlocks - JBCACHE-1103
  +      if (!cache.getInvocationContext().isOriginLocal()) return false;
  +
  +      lock.acquireLock(name, false);
  +      try
  +      {
         MethodCall call = MethodCallFactory.create(MethodDeclarations.existsMethod, name);
         Object resp = callRemote(call);
   
         return resp != null && (Boolean) resp;
      }
  +      finally
  +      {
  +         lock.releaseLock(name);
  +      }
  +   }
   
      public Object put(Fqn name, Object key, Object value) throws Exception
      {
         if (cache.getInvocationContext().isOriginLocal())
         {
  +         lock.acquireLock(name, true);
  +         try
  +         {
            NodeSPI n = cache.peek(name, false);
            if (n == null)
            {
  @@ -153,6 +190,11 @@
               return n.getDirect(key);
            }
         }
  +         finally
  +         {
  +            lock.releaseLock(name);
  +         }
  +      }
         else
         {
            log.trace("Call originated remotely.  Not bothering to try and do a clustered get() for this put().  Returning null.");
  @@ -182,6 +224,9 @@
      {
         if (cache.getInvocationContext().isOriginLocal())
         {
  +         lock.acquireLock(name, true);
  +         try
  +         {
            NodeSPI n = cache.peek(name, true);
            if (n == null)
            {
  @@ -194,6 +239,11 @@
               return n.getDirect(key);
            }
         }
  +         finally
  +         {
  +            lock.releaseLock(name);
  +         }
  +      }
         else
         {
            log.trace("Call originated remotely.  Not bothering to try and do a clustered get() for this remove().  Returning null.");
  
  
  



More information about the jboss-cvs-commits mailing list