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

Manik Surtani msurtani at jboss.com
Tue Sep 5 07:03:26 EDT 2006


  User: msurtani
  Date: 06/09/05 07:03:26

  Modified:    src/org/jboss/cache/factories  InterceptorChainFactory.java
  Log:
  Fixed suppress locking bugs, improved interceptor chain construction, added new interceptor to construct invocation ctx
  
  Revision  Changes    Path
  1.27      +196 -83   JBossCache/src/org/jboss/cache/factories/InterceptorChainFactory.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: InterceptorChainFactory.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/factories/InterceptorChainFactory.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -b -r1.26 -r1.27
  --- InterceptorChainFactory.java	22 Aug 2006 12:27:51 -0000	1.26
  +++ InterceptorChainFactory.java	5 Sep 2006 11:03:26 -0000	1.27
  @@ -8,9 +8,9 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  +import org.jboss.cache.CacheSPI;
   import org.jboss.cache.TreeCache;
  -import org.jboss.cache.interceptors.Interceptor;
  -import org.jboss.cache.interceptors.CallInterceptor;
  +import org.jboss.cache.interceptors.*;
   import org.jboss.cache.loader.CacheLoaderManager;
   
   import java.util.ArrayList;
  @@ -52,14 +52,20 @@
       }
   
   
  -    private Interceptor createInterceptor(String classname, TreeCache cache) throws ClassNotFoundException, IllegalAccessException, InstantiationException
  +   private Interceptor createInterceptor(String classname, CacheSPI cache) throws ClassNotFoundException, IllegalAccessException, InstantiationException
       {
          Class clazz = loadClass(classname);
  +      return createInterceptor(clazz, cache);
  +   }
  +
  +   private Interceptor createInterceptor(Class clazz, CacheSPI cache) throws IllegalAccessException, InstantiationException
  +   {
          Interceptor i = (Interceptor) clazz.newInstance();
  -       i.setCache(cache.getCacheSPI());
  +      i.setCache(cache);
          return i;
       }
   
  +
      /**
       * Adds an interceptor at the end of the chain
       */
  @@ -85,7 +91,9 @@
      {
         ClassLoader cl = getClass().getClassLoader();
         if (cl == null)
  +      {
            cl = ClassLoader.getSystemClassLoader();
  +      }
         return cl.loadClass(classname);
      }
   
  @@ -137,11 +145,11 @@
       * <p/>
       * CallInterceptor is always present at the top, the others may or may not be present
       */
  -   private Interceptor createPessimisticInterceptorChain(TreeCache cache) throws IllegalAccessException, InstantiationException, ClassNotFoundException
  +   private Interceptor createPessimisticInterceptorChain(TreeCache treeCache) throws IllegalAccessException, InstantiationException, ClassNotFoundException
      {
  +      CacheSPI cache = treeCache.getCacheSPI();
         Interceptor call_interceptor = null;
         Interceptor lock_interceptor = null;
  -      // Interceptor create_if_not_exists_interceptor=null;
         Interceptor repl_interceptor = null;
         Interceptor cache_loader_interceptor = null;
         Interceptor cache_store_interceptor = null;
  @@ -152,35 +160,35 @@
         Interceptor txInterceptor = null;
         Interceptor eviction_interceptor = null;
         Interceptor dataGravitatorInterceptor = null;
  +      Interceptor invocationCtxInterceptor = createInterceptor(InvocationContextInterceptor.class, cache);
         Interceptor first = null;
   
  -      call_interceptor = createInterceptor("org.jboss.cache.interceptors.CallInterceptor", cache);
  -      ((CallInterceptor) call_interceptor).setTreeCacheInstance(cache);
   
  -//      if (cache.getBuddyManager() != null && cache.getBuddyManager().isEnableDataGravitation()) dataGravitatorInterceptor = createInterceptor("org.jboss.cache.interceptors.DataGravitatorInterceptor", cache);
  -      if (cache.getBuddyManager() != null) dataGravitatorInterceptor = createInterceptor("org.jboss.cache.interceptors.DataGravitatorInterceptor", cache);
  +      call_interceptor = createInterceptor(CallInterceptor.class, cache);
  +      ((CallInterceptor) call_interceptor).setTreeCacheInstance(treeCache);
         
  -      lock_interceptor = createInterceptor("org.jboss.cache.interceptors.PessimisticLockInterceptor", cache);
  +      if (cache.getBuddyManager() != null)
  +      {
  +         dataGravitatorInterceptor = createInterceptor(DataGravitatorInterceptor.class, cache);
  +      }
   
  -      //create_if_not_exists_interceptor=createInterceptor("org.jboss.cache.interceptors.CreateIfNotExistsInterceptor");
  -      //create_if_not_exists_interceptor.setCache(this);
  +      lock_interceptor = createInterceptor(PessimisticLockInterceptor.class, cache);
   
  -      unlock_interceptor = createInterceptor("org.jboss.cache.interceptors.UnlockInterceptor", cache);
  +      unlock_interceptor = createInterceptor(UnlockInterceptor.class, cache);
   
  -      cacheMgmtInterceptor = createInterceptor("org.jboss.cache.interceptors.CacheMgmtInterceptor", cache);
  +      cacheMgmtInterceptor = createInterceptor(CacheMgmtInterceptor.class, cache);
   
  -      txInterceptor = createInterceptor("org.jboss.cache.interceptors.TxInterceptor", cache);
  +      txInterceptor = createInterceptor(TxInterceptor.class, cache);
   
         switch (cache.getConfiguration().getCacheMode())
         {
            case REPL_SYNC:
            case REPL_ASYNC:
  -            repl_interceptor = createInterceptor("org.jboss.cache.interceptors.ReplicationInterceptor", cache);
  -//                if (!cache.isNodeLockingOptimistic()) cache.setReplicationHandler((Replicatable) repl_interceptor);
  +            repl_interceptor = createInterceptor(ReplicationInterceptor.class, cache);
               break;
            case INVALIDATION_SYNC:
            case INVALIDATION_ASYNC:
  -            repl_interceptor = createInterceptor("org.jboss.cache.interceptors.InvalidationInterceptor", cache);
  +            repl_interceptor = createInterceptor(InvalidationInterceptor.class, cache);
               break;
            case LOCAL:
               //Nothing...
  @@ -192,30 +200,41 @@
         {
            if (cacheLoaderMgr.isPassivation())
            {
  -            activation_interceptor = createInterceptor("org.jboss.cache.interceptors.ActivationInterceptor", cache);
  -            passivation_interceptor = createInterceptor("org.jboss.cache.interceptors.PassivationInterceptor", cache);
  +            activation_interceptor = createInterceptor(ActivationInterceptor.class, cache);
  +            passivation_interceptor = createInterceptor(PassivationInterceptor.class, cache);
            }
            else
            {
  -            cache_loader_interceptor = createInterceptor("org.jboss.cache.interceptors.CacheLoaderInterceptor", cache);
  -            cache_store_interceptor = createInterceptor("org.jboss.cache.interceptors.CacheStoreInterceptor", cache);
  +            cache_loader_interceptor = createInterceptor(CacheLoaderInterceptor.class, cache);
  +            cache_store_interceptor = createInterceptor(CacheStoreInterceptor.class, cache);
            }
         }
   
  -      // load the cache management interceptor first
  +      // load the icInterceptor first
  +      if (first == null) first = invocationCtxInterceptor;
  +
  +      // load the cache management interceptor next
         if (cache.getConfiguration().isUseInterceptorMbeans())
         {
            if (first == null)
  +         {
               first = cacheMgmtInterceptor;
  +         }
            else
  +         {
               addInterceptor(first, cacheMgmtInterceptor);
         }
  +      }
   
         // load the tx interceptor
         if (first == null)
  +      {
            first = txInterceptor;
  +      }
         else
  +      {
            addInterceptor(first, txInterceptor);
  +      }
   
         // create the stack from the bottom up
         if (activation_interceptor != null)
  @@ -223,181 +242,241 @@
            if (!cacheLoaderMgr.isFetchPersistentState())
            {
               if (first == null)
  +            {
                  first = passivation_interceptor;
  +            }
               else
  +            {
                  addInterceptor(first, passivation_interceptor);
            }
         }
  +      }
   
         if (cache_loader_interceptor != null)
         {
            if (!cacheLoaderMgr.isFetchPersistentState())
            {
               if (first == null)
  +            {
                  first = cache_store_interceptor;
  +            }
               else
  +            {
                  addInterceptor(first, cache_store_interceptor);
            }
         }
  +      }
   
         if (repl_interceptor != null)
         {
            if (first == null)
  +         {
               first = repl_interceptor;
  +         }
            else
  +         {
               addInterceptor(first, repl_interceptor);
         }
  +      }
   
         if (unlock_interceptor != null)
         {
            if (first == null)
  +         {
               first = unlock_interceptor;
  +         }
            else
  +         {
               addInterceptor(first, unlock_interceptor);
         }
  +      }
   
         if (activation_interceptor != null)
         {
            if (!cacheLoaderMgr.isFetchPersistentState())
            {
               if (first == null)
  +            {
                  first = activation_interceptor;
  +            }
               else
  +            {
                  addInterceptor(first, activation_interceptor);
            }
  +         }
            else
            {
               if (first == null)
  +            {
                  first = activation_interceptor;
  +            }
               else
  +            {
                  addInterceptor(first, activation_interceptor);
  +            }
               if (first == null)
  +            {
                  first = passivation_interceptor;
  +            }
               else
  +            {
                  addInterceptor(first, passivation_interceptor);
            }
         }
  +      }
   
         if (cache_loader_interceptor != null)
         {
            if (!cacheLoaderMgr.isFetchPersistentState())
            {
               if (first == null)
  +            {
                  first = cache_loader_interceptor;
  +            }
               else
  +            {
                  addInterceptor(first, cache_loader_interceptor);
            }
  +         }
            else
            {
               if (first == null)
  +            {
                  first = cache_loader_interceptor;
  +            }
               else
  +            {
                  addInterceptor(first, cache_loader_interceptor);
  +            }
               if (first == null)
  +            {
                  first = cache_store_interceptor;
  +            }
               else
  +            {
                  addInterceptor(first, cache_store_interceptor);
            }
         }
  +      }
   
          if (dataGravitatorInterceptor != null)
          {
  -           if (first == null) first = dataGravitatorInterceptor;
  -           else addInterceptor(first, dataGravitatorInterceptor);
  +         if (first == null)
  +         {
  +            first = dataGravitatorInterceptor;
  +         }
  +         else
  +         {
  +            addInterceptor(first, dataGravitatorInterceptor);
  +         }
          }
  -
  -      //if(first == null)
  -      // first=create_if_not_exists_interceptor;
  -      //else
  -      // addInterceptor(first, create_if_not_exists_interceptor);
   
         if (first == null)
  +      {
            first = lock_interceptor;
  +      }
         else
  +      {
            addInterceptor(first, lock_interceptor);
  +      }
   
  -      if (cache.isUsingEviction())
  +      if (treeCache.isUsingEviction())
         {
  -         eviction_interceptor = createInterceptor(cache.getEvictionInterceptorClass(), cache);
  +         eviction_interceptor = createInterceptor(treeCache.getEvictionInterceptorClass(), cache);
            if (first == null)
  +         {
               first = eviction_interceptor;
  +         }
            else
  +         {
               addInterceptor(first, eviction_interceptor);
         }
  +      }
   
         if (first == null)
  +      {
            first = call_interceptor;
  +      }
         else
  +      {
            addInterceptor(first, call_interceptor);
  +      }
   
         if (log.isInfoEnabled())
  +      {
            log.info("interceptor chain is:\n" + printInterceptorChain(first));
  +      }
   
         return first;
      }
   
  -   private Interceptor createOptimisticInterceptorChain(TreeCache cache) throws IllegalAccessException, InstantiationException, ClassNotFoundException
  +   private Interceptor createOptimisticInterceptorChain(TreeCache treeCache) throws IllegalAccessException, InstantiationException, ClassNotFoundException
      {
   
  +      CacheSPI cache = treeCache.getCacheSPI();
         Interceptor txInterceptor = null, replicationInterceptor = null, lockInterceptor = null, validationInterceptor = null;
         Interceptor createIfNotExistsInterceptor = null, nodeInterceptor = null, invokerInterceptor = null, activationInterceptor = null;
         Interceptor passivationInterceptor = null, cacheLoaderInterceptor = null, cacheStoreInterceptor = null, first = null;
         Interceptor cacheMgmtInterceptor = null, evictionInterceptor = null, dataGravitatorInterceptor = null;
  +      Interceptor invocationCtxInterceptor = createInterceptor(InvocationContextInterceptor.class, cache);
   
         CacheLoaderManager cacheLoaderManager = cache.getCacheLoaderManager();
         if (cacheLoaderManager != null && cacheLoaderManager.getCacheLoader() != null)
         {
            if (cacheLoaderManager.isPassivation())
            {
  -            activationInterceptor = createInterceptor("org.jboss.cache.interceptors.ActivationInterceptor", cache);
  -            passivationInterceptor = createInterceptor("org.jboss.cache.interceptors.PassivationInterceptor", cache);
  +            activationInterceptor = createInterceptor(ActivationInterceptor.class, cache);
  +            passivationInterceptor = createInterceptor(PassivationInterceptor.class, cache);
            }
            else
            {
  -            cacheLoaderInterceptor = createInterceptor("org.jboss.cache.interceptors.CacheLoaderInterceptor", cache);
  -            cacheStoreInterceptor = createInterceptor("org.jboss.cache.interceptors.CacheStoreInterceptor", cache);
  +            cacheLoaderInterceptor = createInterceptor(CacheLoaderInterceptor.class, cache);
  +            cacheStoreInterceptor = createInterceptor(CacheStoreInterceptor.class, cache);
            }
         }
   
  -      txInterceptor = createInterceptor("org.jboss.cache.interceptors.TxInterceptor", cache);
  +      txInterceptor = createInterceptor(TxInterceptor.class, cache);
   
  -//      if (cache.getBuddyManager() != null && cache.getBuddyManager().isEnableDataGravitation()) dataGravitatorInterceptor = createInterceptor("org.jboss.cache.interceptors.DataGravitatorInterceptor", cache);
  -      if (cache.getBuddyManager() != null) dataGravitatorInterceptor = createInterceptor("org.jboss.cache.interceptors.DataGravitatorInterceptor", cache);
  +      if (cache.getBuddyManager() != null)
  +      {
  +         dataGravitatorInterceptor = createInterceptor(DataGravitatorInterceptor.class, cache);
  +      }
         
         switch (cache.getConfiguration().getCacheMode())
         {
            case REPL_SYNC:
            case REPL_ASYNC:
  -            replicationInterceptor = createInterceptor("org.jboss.cache.interceptors.OptimisticReplicationInterceptor", cache);
  -//                if (!cache.isNodeLockingOptimistic()) cache.setReplicationHandler((Replicatable) replicationInterceptor);
  +            replicationInterceptor = createInterceptor(OptimisticReplicationInterceptor.class, cache);
               break;
            case INVALIDATION_SYNC:
            case INVALIDATION_ASYNC:
  -            replicationInterceptor = createInterceptor("org.jboss.cache.interceptors.InvalidationInterceptor", cache);
  +            replicationInterceptor = createInterceptor(InvalidationInterceptor.class, cache);
               break;
            case LOCAL:
               //Nothing...
         }
   
  -      lockInterceptor = createInterceptor("org.jboss.cache.interceptors.OptimisticLockingInterceptor", cache);
  +      lockInterceptor = createInterceptor(OptimisticLockingInterceptor.class, cache);
   
  -      validationInterceptor = createInterceptor("org.jboss.cache.interceptors.OptimisticValidatorInterceptor", cache);
  +      validationInterceptor = createInterceptor(OptimisticValidatorInterceptor.class, cache);
   
  -      createIfNotExistsInterceptor = createInterceptor("org.jboss.cache.interceptors.OptimisticCreateIfNotExistsInterceptor", cache);
  +      createIfNotExistsInterceptor = createInterceptor(OptimisticCreateIfNotExistsInterceptor.class, cache);
   
  -      nodeInterceptor = createInterceptor("org.jboss.cache.interceptors.OptimisticNodeInterceptor", cache);
  +      nodeInterceptor = createInterceptor(OptimisticNodeInterceptor.class, cache);
   
  -      invokerInterceptor = createInterceptor("org.jboss.cache.interceptors.CallInterceptor", cache);
  -      ((CallInterceptor) invokerInterceptor).setTreeCacheInstance(cache);
  +      invokerInterceptor = createInterceptor(CallInterceptor.class, cache);
  +      ((CallInterceptor) invokerInterceptor).setTreeCacheInstance(treeCache);
   
  -      if (cache.isUsingEviction())
  +      if (treeCache.isUsingEviction())
         {
  -         evictionInterceptor = createInterceptor(cache.getEvictionInterceptorClass(), cache);
  +         evictionInterceptor = createInterceptor(treeCache.getEvictionInterceptorClass(), cache);
         }
   
  +      if (first == null) first = invocationCtxInterceptor;
  +
         if (cache.getConfiguration().isUseInterceptorMbeans())
         {
  -         cacheMgmtInterceptor = createInterceptor("org.jboss.cache.interceptors.CacheMgmtInterceptor", cache);
  +         cacheMgmtInterceptor = createInterceptor(CacheMgmtInterceptor.class, cache);
            if (first == null)
            {
               first = cacheMgmtInterceptor;
  @@ -432,57 +511,87 @@
         if (passivationInterceptor != null && !cacheLoaderManager.isFetchPersistentState())
         {
            if (first == null)
  +         {
               first = passivationInterceptor;
  +         }
            else
  +         {
               addInterceptor(first, passivationInterceptor);
         }
  +      }
   
         // add the cache store interceptor here
         if (cacheStoreInterceptor != null && !cacheLoaderManager.isFetchPersistentState())
         {
            if (first == null)
  +         {
               first = cacheStoreInterceptor;
  +         }
            else
  +         {
               addInterceptor(first, cacheStoreInterceptor);
         }
  +      }
   
         // cache loader interceptor is only invoked if we are ready to write to the actual tree cache
         if (activationInterceptor != null)
         {
            if (first == null)
  +         {
               first = activationInterceptor;
  +         }
            else
  +         {
               addInterceptor(first, activationInterceptor);
  +         }
   
            if (cacheLoaderManager.isFetchPersistentState())
            {
               if (first == null)
  +            {
                  first = passivationInterceptor;
  +            }
               else
  +            {
                  addInterceptor(first, passivationInterceptor);
            }
         }
  +      }
   
         if (cacheLoaderInterceptor != null)
         {
            if (first == null)
  +         {
               first = cacheLoaderInterceptor;
  +         }
            else
  +         {
               addInterceptor(first, cacheLoaderInterceptor);
  +         }
   
            if (cacheLoaderManager.isFetchPersistentState())
            {
               if (first == null)
  +            {
                  first = cacheStoreInterceptor;
  +            }
               else
  +            {
                  addInterceptor(first, cacheStoreInterceptor);
            }
         }
  +      }
   
          if (dataGravitatorInterceptor != null)
          {
  -           if (first == null) first = dataGravitatorInterceptor;
  -           else addInterceptor(first, dataGravitatorInterceptor);
  +         if (first == null)
  +         {
  +            first = dataGravitatorInterceptor;
  +         }
  +         else
  +         {
  +            addInterceptor(first, dataGravitatorInterceptor);
  +         }
          }
   
   
  @@ -543,7 +652,9 @@
         }
   
         if (log.isInfoEnabled())
  +      {
            log.info("interceptor chain is:\n" + printInterceptorChain(first));
  +      }
   
         return first;
      }
  @@ -565,7 +676,9 @@
      public static List asList(Interceptor interceptor)
      {
         if (interceptor == null)
  +      {
            return null;
  +      }
         int num = 1;
         Interceptor tmp = interceptor;
         while ((tmp = tmp.getNext()) != null)
  
  
  



More information about the jboss-cvs-commits mailing list