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

Manik Surtani msurtani at jboss.com
Thu Sep 7 11:42:15 EDT 2006


  User: msurtani
  Date: 06/09/07 11:42:15

  Modified:    src/org/jboss/cache/aop  InternalDelegate.java
  Log:
  Updated options API usage
  
  Revision  Changes    Path
  1.40      +65 -49    JBossCache/src/org/jboss/cache/aop/InternalDelegate.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: InternalDelegate.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/aop/InternalDelegate.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -b -r1.39 -r1.40
  --- InternalDelegate.java	25 Jun 2006 02:10:28 -0000	1.39
  +++ InternalDelegate.java	7 Sep 2006 15:42:15 -0000	1.40
  @@ -8,14 +8,14 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  -import org.jboss.cache.Fqn;
   import org.jboss.cache.CacheException;
   import org.jboss.cache.DataNode;
  -import org.jboss.cache.config.Option;
  +import org.jboss.cache.Fqn;
   import org.jboss.cache.aop.util.ObjectUtil;
  +import org.jboss.cache.config.Option;
   
  -import java.util.Map;
   import java.util.Iterator;
  +import java.util.Map;
   
   /**
    * PojoCache delegation to handle internal cache sotre, that is, the portion that is not part of user's data.
  @@ -24,7 +24,7 @@
    */
   public class InternalDelegate
   {
  -   static Log log=LogFactory.getLog(InternalDelegate.class.getName());
  +   static Log log = LogFactory.getLog(InternalDelegate.class.getName());
      public static final String CLASS_INTERNAL = "__jboss:internal:class__";
      public static final String SERIALIZED = "__SERIALIZED__";
      public static final Fqn JBOSS_INTERNAL = new Fqn("__JBossInternal__");
  @@ -44,10 +44,11 @@
         cache_ = cache;
   
         skipLockOption_ = new Option();
  -      if(cacheOperationSkipLocking)
  +      if (cacheOperationSkipLocking)
         {
            skipLockOption_.setSuppressLocking(true);
  -      } else
  +      }
  +      else
         {
            skipLockOption_.setSuppressLocking(false);
         }
  @@ -68,14 +69,14 @@
      {
         // Not very efficient now since we are peeking every single time.
         // Should have cache it without going to local cache.
  -      return (AOPInstance)get(fqn, AOPInstance.KEY, false);
  +      return (AOPInstance) get(fqn, AOPInstance.KEY, false);
      }
   
      protected AOPInstance getAopInstanceWithGravitation(Fqn fqn) throws CacheException
      {
         // Not very efficient now since we are peeking every single time.
         // Should have cache it without going to local cache.
  -      return (AOPInstance)get(fqn, AOPInstance.KEY, true);
  +      return (AOPInstance) get(fqn, AOPInstance.KEY, true);
      }
   
      AOPInstance initializeAopInstance(Fqn fqn) throws CacheException
  @@ -92,8 +93,8 @@
      int incrementRefCount(Fqn originalFqn, Fqn referencingFqn) throws CacheException
      {
         AOPInstance aopInstance = getAopInstance(originalFqn);
  -      if(aopInstance == null)
  -         throw new RuntimeException("InternalDelegate.incrementRefCount(): null aopInstance for fqn: " +originalFqn);
  +      if (aopInstance == null)
  +         throw new RuntimeException("InternalDelegate.incrementRefCount(): null aopInstance for fqn: " + originalFqn);
   
         int count = aopInstance.incrementRefCount(referencingFqn);
         // need to update it.
  @@ -115,13 +116,16 @@
         // TODO let's find a better way to decouple this.
         if (gravitate && cache_.getBuddyManager() != null)
         {
  -         return cache_.get(fqn, key, gravitateOption_);
  +         cache_.getInvocationContext().getOptionOverrides().setForceDataGravitation(true);
  +         return cache_.get(fqn, key);
         }
         else if (cache_.getCacheLoader() != null)
         {
            // We have cache loader, we can't get it directly from the local get.
  -         return cache_.get(fqn, key, skipLockOption_);
  -      } else
  +         cache_.getInvocationContext().getOptionOverrides().setSuppressLocking(cacheOperationSkipLocking);
  +         return cache_.get(fqn, key);
  +      }
  +      else
         {
            return cache_._get(fqn, key, false);
         }
  @@ -130,14 +134,16 @@
      protected void put(Fqn fqn, Object key, Object value) throws CacheException
      {
         // Use option to ski locking since we have parent lock already.
  -      cache_.put(fqn, key, value, skipLockOption_);
  +      cache_.getInvocationContext().getOptionOverrides().setSuppressLocking(cacheOperationSkipLocking);
  +      cache_.put(fqn, key, value);
   //      cache_.put(fqn, key, value);
      }
   
      protected void put(Fqn fqn, Map map) throws CacheException
      {
         // Use option to ski locking since we have parent lock already.
  -      cache_.put(fqn, map, skipLockOption_);
  +      cache_.getInvocationContext().getOptionOverrides().setSuppressLocking(cacheOperationSkipLocking);
  +      cache_.put(fqn, map);
   //      cache_.put(fqn, key, value);
      }
   
  @@ -145,7 +151,8 @@
      {
         // Use option to ski locking since we have parent lock already.
         // TODO Need to make sure there is no tx here otherwise it won't work.
  -      cache_.put(fqn, key, value, localModeOption_);
  +      cache_.getInvocationContext().getOptionOverrides().setCacheModeLocal(true);
  +      cache_.put(fqn, key, value);
      }
   
   
  @@ -155,12 +162,12 @@
      int decrementRefCount(Fqn originalFqn, Fqn referencingFqn) throws CacheException
      {
         AOPInstance aopInstance = getAopInstance(originalFqn);
  -      if(aopInstance == null)
  +      if (aopInstance == null)
            throw new RuntimeException("InternalDelegate.decrementRefCount(): null aopInstance.");
   
         int count = aopInstance.decrementRefCount(referencingFqn);
   
  -      if(count < -1)  // can't dip below -1
  +      if (count < -1)  // can't dip below -1
            throw new RuntimeException("InternalDelegate.decrementRefCount(): null aopInstance.");
   
         // need to update it.
  @@ -179,19 +186,20 @@
         return getAopInstance(fqn).getRefCount();
      }
   
  -   String getRefFqn(Fqn fqn) throws CacheException {
  +   String getRefFqn(Fqn fqn) throws CacheException
  +   {
         AOPInstance aopInstance = getAopInstance(fqn);
         return getRefFqn(aopInstance, fqn);
      }
   
      String getRefFqn(AOPInstance aopInstance, Fqn fqn) throws CacheException
      {
  -      if(aopInstance == null)
  +      if (aopInstance == null)
            return null;
   
         String aliasFqn = aopInstance.getRefFqn();
   
  -      if(aliasFqn == null || aliasFqn.length() == 0) return null;
  +      if (aliasFqn == null || aliasFqn.length() == 0) return null;
   
         return getRefFqnFromAlias(aliasFqn);
      }
  @@ -199,7 +207,7 @@
      void setRefFqn(Fqn fqn, String internalFqn) throws CacheException
      {
         AOPInstance aopInstance = getAopInstance(fqn);
  -      if(aopInstance == null)
  +      if (aopInstance == null)
            aopInstance = new AOPInstance();
   
         aopInstance.setRefFqn(internalFqn);
  @@ -209,7 +217,7 @@
      void removeRefFqn(Fqn fqn) throws CacheException
      {
         AOPInstance aopInstance = getAopInstance(fqn);
  -      if(aopInstance == null)
  +      if (aopInstance == null)
            throw new RuntimeException("InternalDelegate.getRefFqn(): null aopInstance.");
   
         aopInstance.removeRefFqn();
  @@ -219,7 +227,7 @@
      Object getPojo(Fqn fqn) throws CacheException
      {
         AOPInstance aopInstance = getAopInstance(fqn);
  -      if(aopInstance == null)
  +      if (aopInstance == null)
            return null;
   
         return aopInstance.get();
  @@ -229,7 +237,7 @@
      {
         // This is for buddy replication
         AOPInstance aopInstance = getAopInstanceWithGravitation(fqn);
  -      if(aopInstance == null)
  +      if (aopInstance == null)
            return null;
   
         return aopInstance.get();
  @@ -238,7 +246,7 @@
      void setPojo(Fqn fqn, Object pojo) throws CacheException
      {
         AOPInstance aopInstance = getAopInstance(fqn);
  -      if(aopInstance == null)
  +      if (aopInstance == null)
         {
            aopInstance = new AOPInstance();
            put(fqn, AOPInstance.KEY, aopInstance);
  @@ -256,7 +264,7 @@
   
      void setPojo(Fqn fqn, Object pojo, AOPInstance aopInstance) throws CacheException
      {
  -      if(aopInstance == null)
  +      if (aopInstance == null)
         {
            aopInstance = new AOPInstance();
            put(fqn, AOPInstance.KEY, aopInstance);
  @@ -269,7 +277,8 @@
      /**
       * We store the class name in string.
       */
  -   void putAopClazz(Fqn fqn, Class clazz) throws CacheException {
  +   void putAopClazz(Fqn fqn, Class clazz) throws CacheException
  +   {
         put(fqn, CLASS_INTERNAL, clazz);
      }
   
  @@ -277,21 +286,23 @@
       * We store the class name in string and put it in map instead of directly putting
       * it into cache for optimization.
       */
  -   void putAopClazz(Fqn fqn, Class clazz, Map map) throws CacheException {
  +   void putAopClazz(Fqn fqn, Class clazz, Map map) throws CacheException
  +   {
         map.put(CLASS_INTERNAL, clazz);
      }
   
  -   Class peekAopClazz(Fqn fqn) throws CacheException {
  -      return (Class)get(fqn, CLASS_INTERNAL);
  +   Class peekAopClazz(Fqn fqn) throws CacheException
  +   {
  +      return (Class) get(fqn, CLASS_INTERNAL);
      }
   
      boolean isAopNode(Fqn fqn) throws CacheException
      {
         // Use this API so it doesn't go thru the interceptor.
         DataNode node = cache_.peek(fqn);
  -      if(node == null) return false;
  +      if (node == null) return false;
   
  -      if( node.get(AOPInstance.KEY) != null )
  +      if (node.get(AOPInstance.KEY) != null)
            return true;
         else
            return false;
  @@ -306,21 +317,24 @@
      void cleanUp(Fqn fqn, boolean evict) throws CacheException
      {
         // We can't do a brute force remove anymore?
  -      if(!evict)
  +      if (!evict)
         {
  -         if( !cache_._get(fqn).hasChildren() )
  +         if (!cache_._get(fqn).hasChildren())
            {
               // remove everything
               cache_.remove(fqn);
  -         } else
  +         }
  +         else
            {
               // Assume everything here is all PojoCache data for optimization
               cache_.removeData(fqn);
  -            if (log.isTraceEnabled()) {
  +            if (log.isTraceEnabled())
  +            {
                  log.trace("cleanup(): fqn: " + fqn + " is not empty. That means it has sub-pojos. Will not remove node");
               }
            }
  -      } else
  +      }
  +      else
         {
            // This has to use plainEvict method otherwise it is recursively calling aop version of evict.
            cache_.plainEvict(fqn);
  @@ -337,7 +351,7 @@
   
      Fqn getInternalFqn(String fqn)
      {
  -      if(fqn == null || fqn.length() == 0)
  +      if (fqn == null || fqn.length() == 0)
            throw new IllegalStateException("InternalDelegate.getInternalFqn(). fqn is either null or empty!");
   
         String indirectFqn = getIndirectFqn(fqn);
  @@ -361,7 +375,7 @@
      {
         String indirectFqn = getIndirectFqn(oldFqn);
         Fqn tmpFqn = getInternalFqn(oldFqn);
  -      if(cache_.exists(tmpFqn, indirectFqn)) // No need to update if it doesn't exist.
  +      if (cache_.exists(tmpFqn, indirectFqn)) // No need to update if it doesn't exist.
         {
            put(tmpFqn, indirectFqn, newFqn);
         }
  @@ -374,7 +388,7 @@
   
      String getRefFqnFromAlias(String aliasFqn) throws CacheException
      {
  -      return (String)get(getInternalFqn(aliasFqn), aliasFqn, true);
  +      return (String) get(getInternalFqn(aliasFqn), aliasFqn, true);
      }
   
      Fqn getNextFqnInLine(Fqn currentFqn) throws CacheException
  @@ -402,14 +416,14 @@
         cache_.put(newFqn, value);
   
         Map children = node.getChildren();
  -      if(children == null || children.size() == 0)
  +      if (children == null || children.size() == 0)
         {
            cache_.remove(thisFqn);
            return; // we are done
         }
   
         Iterator it = children.keySet().iterator();
  -      while(it.hasNext())
  +      while (it.hasNext())
         {
            Object key = it.next();
            Fqn thisChildFqn = new Fqn(thisFqn, key);
  @@ -423,11 +437,13 @@
   
      /**
       * Test if this internal node.
  +    *
       * @param fqn
       */
  -   public static boolean isInternalNode(Fqn fqn) {
  +   public static boolean isInternalNode(Fqn fqn)
  +   {
         // we ignore all the node events corresponding to JBOSS_INTERNAL
  -      if(fqn.isChildOrEquals(InternalDelegate.JBOSS_INTERNAL)) return true;
  +      if (fqn.isChildOrEquals(InternalDelegate.JBOSS_INTERNAL)) return true;
   
         return false;
      }
  
  
  



More information about the jboss-cvs-commits mailing list